Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Feb 29, 2016 · 2 comments
Closed

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

ghost opened this issue Feb 29, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 29, 2016

`
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
Copy link

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
Copy link
Author

ghost commented Mar 1, 2016

thanks , Walter.

@ghost ghost closed this as completed Mar 2, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant