草庐IT

my_function_with_global_var

全部标签

javascript - 顺序依赖 : jQuery is not defined with browserify

我正在尝试使用/js/lib/stellar.jquery.js中的插件:var$=require('jquery');require('./lib/stellar.jquery')$(function(){$.stellar();});当我运行它时,虽然我得到jQueryisnotdefined。我认为stellarjQuery插件在jq库之前加载。在stellar插件的底部有这段代码:...//Exposethepluginclasssoitcanbemodifiedwindow.Stellar=Plugin;}(jQuery,this,document));将“jQuery”更改

javascript - 为什么 JavaScript 中的参数前面没有 var 关键字?

这可能是个愚蠢的问题,但为什么JavaScript中的函数参数前面没有var关键字?为什么:functionfooAnything(anything){return'foo'+anyThing;}而不是:functionfooAnything(varanything){return'foo'+anyThing;}我感觉答案是因为规范就是这么说的,但仍然... 最佳答案 大多数动态类型编程语言没有在参数列表中有明确的变量。var关键字的目的是区分“我正在设置一个现有变量”和“我正在创建一个新变量”,如varx=17;//newvari

JavaScript 如果 var 存在

我想要我的代码,这样如果一个特定的变量存在,它就会执行一个Action,否则它将被忽略并继续前进。我的代码的问题是,如果特定的var不存在,它会导致错误,大概会忽略JavaScript代码的其余部分。例子varYouTube=EpicKris;if((typeofYouTube)!='undefined'&&YouTube!=null){document.write('YouTube:'+YouTube);}; 最佳答案 try{if(YouTube){console.log("exist!");}}catch(e){}consol

javascript - 在 Javascript 中围绕 Function() 创建沙箱

我可以限制字符串生成函数(使用Function构造函数)对父级/全局范围的访问吗?例如:下面的代码原样打印false,因为该函数正在存储/修改窗口中的变量a。window.a=4;Function("a=3;")()console.log(a===4);我可以限制对窗口/父范围的访问并让它打印出“true”吗? 最佳答案 这是一个额外的想法,与Esailija的提议一起可能会非常强大(请参阅他对讨论的回答的评论)。您可以创建虚拟iframe并使用其Function功能。默认情况下,用它创建的函数只能访问iframe的范围,尽管它仍然

javascript - 为什么我得到 ".push not a function"?

我的代码有什么问题?functionlongestConsec(strarr,k){varcurrentLongest="";varcounter=0;varoutPut=[];if(strarr.length===0||k>strarr.length||kcurrentLongest){currentLongest=strarr[i];}}while(currentLongest!==strarr[counter]){counter=counter+1}for(varj=0;j我一直收到“outPut.push不是一个函数”。 最佳答案

javascript - JavaScript 中 "anonymous function"和 "function literal"的区别?

本书LearningJavaScript定义匿名函数如下...Functionsareobjects.Assuch,youcancreatethem-justlikeaStringorArrayorothertype-byusingaconstructorandassigningthefunctiontoavariable.Inthefollowingcode,anewfunctioniscreatedusingtheFunctionconstructor,withthefunctionbodyandargumentpassedinasarguments:varsayHi=newFun

javascript - 使用 require.js 时访问 "global"mocha.js 函数

我将Mocha.js包含在优秀的useshim中对于基于Require.js的网站。在使用Require.js时如何访问Mocha声明的define()和it()BDD函数?这是一个基本的代码示例:测试.js:varmocha=require('use!mocha'),testFile=require('testFile.js')mocha.setup('bdd');mocha.run();测试文件.js:define(function(require){//describe()andit()arenotavailabledescribe('Book',function(){it('s

javascript : sending custom parameters with window. open() 但它不工作

functionopen_win(){window.open("http://localhost:8080/login","mywindow")}你好,单击按钮,我将打开一个新网站(我的网站)我有两个文本字段(一个文本字段和另一个密码字段),我试图将这些值发送到另一个打开的窗口。但它并没有像我想要的那样工作。我试过以下方法1.window.open("http://localhost:8080/login?cid='username'&pwd='password'","mywindow")2.window.open("http://localhost:8080/login","mywi

javascript - Coffeescript 中的 var self = this

我在使用Coffeescript时遇到了一些范围问题。drawFirstLine:(currentAngle)->currentAngle=currentAngle#=1switch@type#set@endAngletopickuplateron#Math.PI*2istheendpointofacircledividedbysecondstimescurrentsecondswhen"seconds"then@endAngle=Math.PI*2/60*@secondswhen"minutes"then@endAngle=Math.PI*2/60*@minuteswhen"hour

javascript - 不匹配的匿名 define() 模块 : function() {"use strict";return axe}

出于某种原因我有这个奇怪的错误:"Mismatchedanonymousdefine()module:function(){"usestrict";returnaxe}http://requirejs.org/docs/errors.html#mismatch"设置了一些JS断点后,发现错误源在这里:a[browserlink]Line363:/*!aXev2.0.5*Copyright(c)2016DequeSystems,Inc.*...etc...*/...etc...&&define([],function(){"usestrict";returnaxe}),...etc...