首页 > Web开发 > 详细

jquery--this

时间:2017-05-24 19:02:19      阅读:138      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type=text/javascript charset=utf-8>
var x = "x";
var y = "yyy";
function F(a){
    this.n = fsfsf;
    this.sc = 4;
    var i = new init(this);//F(),this指的是window
    i.ii = "ii";
}

function init(o){
    alert(o);//[object Window]
    alert(sc);//4
    alert(o.x);//x
    alert(o.y);//yyy
    this.n = o.sc;  //init方法不是对象调用的时候,new的时候this指的是本类的对象,不是window对象
    this.name = "namename";
    this.o = o;
    that = this;
    return function(){
        alert("333" + this.n);//undefined,this是这个匿名函数的对象
        alert("333" + that.n);
        this.h = that;
        this.k = that.n;
        this.a = that.a
    }
    ;
}
alert(1);
var d = F(3);
alert(window.n)//fsfsf
alert(2);
var dd = new d();
alert(window.name)//
alert(3);
alert(dd.k);//4
alert(dd.h.name);//namename   
alert(dd.a.n);//fsfsf 
alert(window.k);//undefined
alert(window.h.name);//Cannot read property ‘name‘ of undefined   
alert(window.a.n);//Cannot read property ‘n‘ of undefined   



function F(a){
    this.n = 1;
    this.sc = 4;
    return new init(this);//this是F对象
}

function init(a){
    alert("111" + a.sc);//4
    this.n = a.sc;
    return {
        k : this.n
    }
}
alert(1);
var d = F(3);
alert(d.k); //4


function F(a){
    this.n = 1;
    this.sc = "scscsc";
}
var d = new F();
alert(window.sc);//undefined
</script>
</head>
<body>
</body>
</html>

 

jquery--this

原文:http://www.cnblogs.com/yaowen/p/6900332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!