JavaScript讓人很頭疼

來源:互聯網
上載者:User

想當年搞C++的物件導向時,很多問題只要花一些時間就可以搞定,想的很清楚明白。可是最近搞JavaScript好多問題搞不清楚,會用卻搞不清楚很讓人不爽。

function Shape(){  this.area = function(){};}function Point(){  this.x = 0;  this.y = 0;}var p = new Point;console.log(p.prototype);    //為啥是undefineconsole.log(p.constructor);  //為啥又是指向Point的functionconsole.log("-----------------------------");p.prototype = new Shape();console.log(p.area);          //為啥又是undefine,不是設定了原型對象嘛,我操Point.prototype = new Shape();console.log(p.area);          //TMD還是不行,我設定了類型的原型對象啊Point.prototype.area = function(){};console.log(p.area);          //你媽,為什麼啊var p2 = new Point;console.log(p2.area);         //我操,這時又可以了@#¥%……&*(

 

Output:

undefinedfunction Point() { this.x = 0; this.y = 0; }-----------------------------undefinedundefinedundefinedfunction () { }

 

我什麼時候能搞清楚啊!我看了一堆文章,我TMD的還是有5年以上編程經驗的Programmer,我居然還精通於物件導向編程。遇到JavaScript我栽了。你還別給哥一段代碼說:這樣寫就對了,哥知道怎麼樣寫可以,但哥搞不清楚他內部的關係啊,有沒有!!!誰能畫張圖將上面的參考關聯性,閑置對象,類型對象都畫出來,讓我醍醐灌頂一次吧。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.