名字
var x = {
name:"t-io",
show:function(id){
console.log(this.name + id);
},
hide:function(id){
console.log(this.location.href);
console.log("隐藏" + id);
}
}
x.show.call(a, 1314); //将打印t-io1314
x.hide.call(window, 3344);
apply方法和call方法有些相似,但第二个参数必须是一个数组,其它原则参考call()
var x = {
name:"t-io",
show:function(id){
console.log(this.name + id);
},
hide:function(id, id2){
console.log(this.location.href);
console.log("隐藏" + id + id2);
}
}
x.show.apply(a, [1314]); //将打印t-io1314
x.hide.apply(window, [3344, 6688]);
看一个例子大家就能明白bind是个什么了
var log = console.log.bind(console);
log("666"); //等价于console.log("666");
t-io官网利用后端渲染技术和bind()方法,动态选择要不要打印日志,此思考大家可以参考,在生产环境尽量不打日志
<#if console.log == true >
var log = console.log.bind(console);
<#else>
var log = function () { };
</#if>
<#if console.info == true >
var info = console.info.bind(console);
<#else>
var info = function () { };
</#if>
<#if console.error == true >
var error = console.error.bind(console);
<#else>
var error = function () { };
</#if>
最新评论 我的评论
t-io为本站提供HTTP、WebSocket、Socket、页面渲染与压缩等服务,nginx为本站提供反向代理服务
© 2017-2023 钛特云 版权所有 | 浙ICP备17032976号 | 浙公网安备 33011802002129号