From: Stone Zhong on
Am I missing something?
From: Stone Zhong on
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
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
Stone Zhong wrote:
> Am I missing something?

Apparently. I can see all of your posts.