I have the following class:
var Person = Class.create({
initialize: function(name) {
this.name = name;
},
say: function(message) {
return this.name + ': ' + message;
}
});
If I’m to declare a new instance variable, do I have to explictly state the datatype?
JavaScript does not have datatype declarations. It’s been a while since I’ve used prototypejs, but I think you can do something like this:
Using the variable without declaration (as in your code sample) will work, but it can be a bit more clear which properties are being used if they are also declared separately. Plus, you can give them default values this way.