From: Stone Zhong on 18 May 2010 02:31 Am I missing something?
From: Stone Zhong on 18 May 2010 02:35 Here is my deleted post: Hi there, I am reading the book "The Concise Guide to Dojo" and I saw some code like below on page 11: decafbad.school.PersonClassic.prototype = {... I personally did a test like below ==== this code does not work === function Person(name) { this.name = name; Person.prototype = { sayHi: function() { alert('hi ' + this.name); } }; } var a = new Person("JavaScript"); a.sayHi(); // I got error a.sayHi is not a function however, if I change the code to below style , it worked, function Person(name) { this.name = name; Person.prototype.sayHi = function() { alert('hi ' + this.name); } var a = new Person("JavaScript"); a.sayHi(); My conclusion is, a function's prototype already has some hidden properties which might be important, replace function's prototype is not good idea, only add property to function's prototype.
From: Stone Zhong on 18 May 2010 02:37 On May 17, 11:31 pm, Stone Zhong <stone.zh...(a)gmail.com> wrote: > Am I missing something? Here is my post: Hi there, ==== this code does not work === function Person(name) { this.name = name; Person.prototype = { sayHi: function() { alert('hi ' + this.name); } }; } var a = new Person("JavaScript"); a.sayHi(); // I got error a.sayHi is not a function
From: David Mark on 18 May 2010 05:56 Stone Zhong wrote: > Am I missing something? Apparently. I can see all of your posts.
|
Pages: 1 Prev: replace Function.prototype does not work Next: My apologize for multiple posting last night |