码迷,mamicode.com
首页 > 其他好文 > 详细

这几道题,你会做吗?

时间:2014-12-21 13:51:52      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

1.考点:上下文

技术分享
var a =1;
var json = {
a:10,
val:function(){
alert(this.a*=2);
}
}
json.val();
var b = json.val;
b();
alert("stop-stop")
json.val.call(window);
alert(window.a + json.a);
技术分享

2.考点:属性

技术分享
var a =1;
var json = {
a:10,
val:function(){
alert(a*=2);
}
}
json.val();
var b = json.val;
b();
alert("stop-stop")
alert(window.a + json.a);
技术分享

3.考点:原形链

技术分享
function t1(name){
if(name) this.name = name;
}
function t2(name){
this.name = name;
}
function t3(name){
this.name = name||"test";
}
t1.prototype.name = "yupeng";
t2.prototype.name = "yupeng";
t2.prototype.name = "yupeng";
alert(new t1().name +new t2().name+new t3().name);
技术分享

4.考点:闭包

技术分享
var test = (function(a){
return function(){
alert(a*2);
}
})(2);

test(20);
技术分享

这几道题,你会做吗?

标签:

原文地址:http://www.cnblogs.com/studies/p/4176346.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!