[問題][js] closure 和 prototype的差別~
(問題一)
在這個網頁==>
http://caterpillar.onlyfun.net/Gossip/AjaxGossip/ConstructorPrototype.html
裡提到的 getSize 的建立方式分別為closure 和 prototype的方式
請問差別在哪呢? 不知怎麼理解^^"
是記憶體的佔用方式有差嗎?還是?
(問題二)
在犀牛書上看到的
function Rectangle(w,h) {
this.width = w;
this.height = h;
this.area = function() { return this.width*this.height;}
}
和
function Rectangle(w,h) {
this.width = w;
this.height = h;
}
Rectangle.protoype.area = function() { return this.width* this.height; }
這兩種的area差別要怎麼看呢?
煩請各位前賢講解一下了<(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.95.110
※ 編輯: kevintwo 來自: 140.113.95.110 (06/03 11:14)
※ 編輯: kevintwo 來自: 140.113.95.110 (06/03 11:19)
討論串 (同標題文章)
完整討論串 (本文為第 1 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章