prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 639 forks source link

version 1.7.3 --- the instance can not put in Array #310

Closed ghost closed 8 years ago

ghost commented 8 years ago

` var Person = Class.create(); Person.prototype = { initialize: function(name) { this.name = name; }, say: function(message) { return this.name + ': ' + message; } };

var guy1 = new Person('Miro1'); var guy2 = new Person('Miro2'); list=[guy1,guy2] for(var i in list){ var item = list[i]; item.say('hi'); // i just got : say is not a function } `

walterdavis commented 8 years ago

Instead of blowing away the prototype of your new class, why not use the other tools that Prototype provides:

Person.addMethods({
  initialize: function(name){
    this.name = name;
  },
  say: function(message){
    return this.name + ': ' + message;
  }
});

And then you should be able to do this.

Walter

ghost commented 8 years ago

thanks , Walter.