jquery--this

來源:互聯網
上載者:User

標籤:object   var   bsp   can   round   org   function   charset   efi   

<!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)//fsfsfalert(2);var dd = new d();alert(window.name)//空alert(3);alert(dd.k);//4alert(dd.h.name);//namename   alert(dd.a.n);//fsfsf alert(window.k);//undefinedalert(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); //4function F(a){    this.n = 1;    this.sc = "scscsc";}var d = new F();alert(window.sc);//undefined</script></head><body></body></html>

 

jquery--this

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.