首页 > TAG信息列表 > use-strict

Javascript-为什么严格模式会使如此简单的动作如此不同?

有一个非常简单的算法,在两种情况下,工作原理出乎意料地不同,具体取决于“使用严格”的使用. 情况1: 如果func()声明在严格模式内,则控制台日志原语 "use strict"; // strict mode is on Object.prototype.func = function() { return this; } // do nothing with the object con

javascript-如何使用JSLint全局设置“严格使用”

我是javascript新手,正在尝试通过JSLint进行验证. 我应该在哪里放置“严格使用”以在全球范围内使用它并进行验证? 这给了我错误“在语句位置出现意外的表达式’use strict’”. "use strict"; console.log('doing js in head-section'); function helloWorld() {

javascript – 如何删除babel添加的全局“use strict”

我正在使用“使用严格”的函数形式,并且不希望Babel在翻译后添加的全局形式.问题是我使用的是一些没有使用“use strict”模式的库,并且在脚本连接后可能会抛出错误解决方法:巴别5 你将黑名单列为“useStrict”.例如,这是Gruntfile中的一个示例: babel: { options: { b

javascript – 启用“use strict”后,为什么我可以在使用prompt()时不使用let来分配变量

我写了“用严格”;在我的脚本的顶部. 我不能写num = 5;因为我得到了ReferenceError:找不到变量:num. 为了解决这个问题,我可以写let num = 5;. 使用该逻辑,为什么我可以写name = prompt(“你叫什么名字?”);? 我不应该写let name = prompt(“你叫什么名字?”)?解决方法:假设您在浏览器中

javascript – “use strict”继承/范围

//Global Scope "use strict"; //1 function A() { "use strict"; //2 function innerA() { "use strict"; //3 } } 我只是想知道: Is doing use strict at //1 is enough or do we have to be explicit at all places like /

JSLint严格违规.面向对象的Javascript挫折

我正在努力学习在JavaScript中进行面向对象编程并严格违反JSLint.我知道我在非全局环境中使用它(或者那种效果……),但我不知道如何正确地做到这一点.这是我的代码: function piece(color, type, x, y, captured, hasMoved) { "use strict"; this.color = color; this.

Javascript:原型方法错误?

这段代码我得到“TestFunc is not defined”错误… /* my_object.js */ "use strict"; function MyObject (param) { this.param = param; } MyObject.prototype.TestFunc = function () { console.log ('in TestFunc'); } MyObject.prototype.RealFunc =