最近,我通过Crockford的jslint 输入了一些我的笔记本代码, 它犯了以下错误:
第1行字符1:缺少“严格使用”的语句。
某些搜索, 我意识到有些人在他们的 javascript 代码中添加了“ 严格使用 ” ; 。 一旦我添加了该语句, 错误就不再出现。 不幸的是, Google 并没有揭示此字符串语句背后的大部分历史。 当然, 它肯定与浏览器如何解读该语句有关, 但我不知道效果会是什么 。
那么,什么是“严格使用”;什么是“严格使用”;一切,它意味着什么,它是否仍然相关?
当前的任何浏览器是否响应“ 严格使用 ” ; 字符串, 或是否未来使用 ?
如果人们担心使用严格使用,
浏览器中的 5 个“ 限制模式” 支持 。 这是什么意思 ? novogeek. com - krishna 的 Webb 。
讨论浏览器支持, 但更重要的是如何安全处理:
function isStrictMode(){
return !this;
}
/*
returns false, since 'this' refers to global object and
'!this' becomes false
*/
function isStrictMode(){
"use strict";
return !this;
}
/*
returns true, since in strict mode the keyword 'this'
does not refer to global object, unlike traditional JS.
So here, 'this' is 'undefined' and '!this' becomes true.
*/