I have a function object:
var myObj=function(){
};
myObj.prototype = {
availableColor: function(i){
return "red_"+i;
}
getColor: function(){
var c = availableColor('3'); //Error: availableColor is not a function
...
}
}
When I call availableColor(i)
inside getColor()
function, I got error availableColor is not a function....
I also tried to use var c = this.availableColor('3');
and
var self=this
in the constructor, then var c = self.availableColor('3');
But, none of these help. what is the reason?
If you just want to add methods to myObj, just do:
The way you use
prototype
will makemyObj
an constructor:var o = new myObj()
.myObj
won't have those methods.EDIT
Another approach: