jjzjj

javascript - Function.prototype.call 在严格模式之外改变 this 的类型;为什么?

varexample=function(){console.log(typeofthis);returnthis;};在严格模式下:example.call('test')#prints'string'否则,example.call('test')#prints'object'然而,console.log(example.call('test'))版画test(如你所料)为什么Function.call更改typeof'test'==='string'绑定(bind)到this里面example? 最佳答案 当使用call()并将t

javascript - jQuery 回调 - 严格违反

在strictmodeoutlinedhere中,我得到关于this不在method中的基本想法,但老实说,它有点博学。因此,用更平淡的术语来说:我有一个这样的处理程序:$('.myClass').one('keyup',function(){var$this=$(this);etcetc});我想改成这样:functionmyFunction(){var$this=$(this);etcetc};$('.myClass1').one('keyup',myFunction);$('.myClass2').one('keyup',myFunction);etc它不喜欢它,因为在stric

javascript - JS : What is 'this' coercion? use-strict 和那个有什么关系?

我在网站上阅读了以下内容:Use-stricthasanadvantage.Iteliminatesthiscoercion.Withoutstrictmode,areferencetoathisvalueofnullorundefinedisautomaticallycoercedtotheglobal.Thiscancausemanyheadfakesandpull-out-your-hairkindofbugs.Instrictmode,referencingaathisvalueofnullorundefinedthrowsanerror.这到底是什么意思?use-strict

JavaScript 'use strict' ;内部函数

在ChromeDevConsole中测试了一些js代码,我有点困惑。我知道在严格模式中,当引用this关键字时不是对象方法的函数应该接收undefined而不是全局对象.functiontest(){"usestrict";returnthis===undefined;}test();输出假。"usestrict";functiontest(){returnthis===undefined;}test();仍然错误。(functiontest(){"usestrict";returnthis===undefined;}());输出真。只是想澄清一下。ʕ•ᴥ•ʔ我是js新手。

javascript - 将 'use strict' 放在 Browserify 包中的什么位置

在Browsersifybundle(包含来自许多文件的许多模块)中,usestrict应该出现在哪里以确保整个bundle在严格模式下运行? 最佳答案 当您需要以统一的方式更改browserify输出时,答案通常是使用转换。strictify似乎可以满足您的需求。 关于javascript-将'usestrict'放在Browserify包中的什么位置,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com

javascript - 是否可以强制 JavaScript 在使用前声明变量?

如果在没有先声明的情况下使用变量,是否可能通过在JavaScript代码中使用一些指令来抛出警告或错误?如果不可能,是否有一些插件可以强制Eclipse(或任何其他IDE)检测未声明的变量? 最佳答案 是的,可以使用strictmode来做到这一点.您可以通过在文件或函数的顶部放置一个包含字符串文字"usestrict"的语句来启用它,以便为该范围启用严格模式。"usestrict";doesNotExist=42;//thisthrowsaReferenceError此功能现在是supported所有更新的浏览器。较旧的浏览器不会

javascript - ES5 "strict"和 arguments.callee

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Whywasthearguments.callee.callerpropertydeprecatedinJavaScript?在ES5严格模式(即“usestrict”)中,引用当前函数的arguments.callee变量不再可用。对于递归函数,使用函数自己的名称显然是明智的。然而,有时我可能想使用arguments.callee的属性(即.length、.prototype)而不必使用名称当前功能。谁能解释通过删除它(据称)解决了哪些明显的问题?

javascript - "Bad Line Breaking"是否已被 "use strict"淘汰?

请假设“使用严格”;并假设JSLint已打开并且错误不能被忽略。我发现运算符和','启动的列表更具可读性,例如:vari=0,j=1,someLongVariablename1,someLongVariablename2,someLongVariablename3,someLongVariablename4;if(('dcr'===cmd&&(action)&&('get'===actionHttp||'post'===actionHttp)&&whatever){...}因此我的问题是:“BadLineBreaking”是否已因“usestrict”而过时?已编辑:“使用严格”;不会

javascript - John Resig 的简单类实例化和 "use strict"

引用:http://ejohn.org/blog/simple-class-instantiation///makeClass-ByJohnResig(MITLicensed)functionmakeClass(){returnfunction(args){if(thisinstanceofarguments.callee){if(typeofthis.init=="function")this.init.apply(this,args.callee?args:arguments);}elsereturnnewarguments.callee(arguments);};}我想知道是否有

javascript - 为什么 "use strict"(JavaScript) 没有检测到未声明的变量?

我正在努力获得“严格使用”;指示工作,并遇到了一些麻烦。在下面的文件中,FireFox9将(正确地)检测到someVar未在第3行声明,但未能检测到theVar未在第19行声明。我很困惑为什么会这样。"usestrict";//thiswillcausethebrowsertocheckforerrorsmoreaggresivelysomeVar=10;//thisDOESgetcaught//LINE3//debugger;//thiswillcauseFireBugtoopenatthebottomofthepage/window//itwillalsocausethedebug