"use strict"是JavaScript中一个非常好的特性,而且非常容易使用。
如果你仅想在一个函数中使用:
这段代码会抛出一个错误因为 eyeLeft 出现了两次。这比你用眼睛去找错误要快多了。
未声明变量
重复的参数
限制函数中的arguments
使用方法
// file.js
"use strict"
function doStuff(){
// use strict is enabled here!
}
这样佻的file.js都会应用上"use strict"模式。如果你仅想在一个函数中使用:
// file.js
function a(){
"use strict";
// use strict is enabled in this context
function nestedFunction(){
// and here too
}
}
好处
检查对象中的重复键var zombie = {
eyeLeft : 0,
eyeRight: 1,
// ... a lot of keys ...
eyeLeft : 1
}
这段代码会抛出一个错误因为 eyeLeft 出现了两次。这比你用眼睛去找错误要快多了。
未声明变量
plane = 5;
你现在已经知道忘记在这个变量前面加var了。不过如果你不知道,调试起来是非常痛苦的,因为这个变量是声明在全局上下文(global context)中的,而且可能被其他地方改掉。想象一下,如果你声明了一个全局的 i, 在嵌套循环中可能会引起混乱。重复的参数
function run(fromWhom, fromWhom){}
注意fromWho出现了两次,因此会抛出一个错误。限制函数中的arguments
var run = function(fromWhom){
arguments[0] = 'alien';
alert(fromWhom);
}
run('zombie');
// alert: 'alien';
现在你可以使用"use strict"var run = function(fromWhom){
"use strict";
arguments[0] = 'alien';
alert(fromWhom);
}
run('zombie');
// alert: 'zombie';
arguments[0] = 'alien' 改变了参数fromWhom,use strict 又节约了你的时间。
列表
##
@黎旦危 #0
-
标题
#
--
`
`
`
好
是的范德萨
use strict
use strict
xxxx
哪里体现了”节约时间“呢?
@Sigma #9
让小白避免语法错误吧,不过我不喜欢这个东西,限制很多,不够灵活,还降低了VM的性能
user strict; (function(){alert(5)})();
rrrrerwrwrw3ddwedwedw`dwedwedwe![插入图片描述][1]wdwedwedwedwe`
`
##
@施厅广 #10
这明明提高了性能
ssssssssss**加粗sss文本**ssssssss添加链接
用严格模式好呢,还是不用严格模式好呢!
主要是现在已经习惯非严格模式了,比如this在函数里面指向window
@dennis2 #11
你说了个几把
@武丈令 #4
.
wtf
user strict; (function(){alert(5)})();
sadflka asdfsdf
@谢成仿 #19
66666
333333
ssss
console.error(this,this)
在这里输入代码阿萨德阿萨德撒旦按时打`萨达 萨达按时打`
@陈皮丘 #30
111
@卢叹毕 #29
alert('xx');
&……¥&¥……
awewae
erwe
在这里输入代码
恶趣味群二群二
sdadasdasdasdasda
142054
还可以这样吗
"use strict"
@金欢芒 #7 11111
sdassdasd sadad
inmsdsdsdsdkkf
dfkldsfskdfsdfl
加粗文本
这里是代码么。 public class BundleConfig { // 有关捆绑的详细信息,请访问 https://go.microsoft.com/fwlink/?LinkId=301862 public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/Scripts/jquery-{version}.js"));
// 使用要用于开发和学习的 Modernizr 的开发版本。然后,当你做好 // 生产准备就绪,请使用 https://modernizr.com 上的生成工具仅选择所需的测试。 bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/Scripts/bootstrap.js", "~/Scripts/respond.js")); bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/bootstrap.css", "~/Content/site.css")); } }
1111
@褚击计 #41
在这里输入代码
![
]1
--
@我操 #6
出现在 v
console.log("hello word")
http://img.zcool.cn/community/012ef25a26d4c3a80120ba385d5537.jpg@1280w_1l_2o_100sh.jpg
alert(1)
import functools def showValue(*args,**kwargs): print(args) print(kwargs)
p = showValue
p(1,2,3)
p = functools.partial(showValue,1,2,3) p() #(1, 2, 3) {}
p(id=123) #(1,2,3) {'id':123}
import functools
def showValue(*args,**kwargs): print(args) print(kwargs)
p = showValue
p(1,2,3)
p = functools.partial(showValue,1,2,3) p() #(1, 2, 3) {}
p(id=123) #(1,2,3) {'id':123}
添加链接添加链接