Please consider this code in javascript:
function Selector() {
this.Status = "";
this.Groups = new Array();
this.Errors = new Array();
}
I want to add a method for Groups property of the Selector class and use it for any instance. How can i do this?
Please be aware that i write this code:
function Selector() {
this.Status = "";
this.Groups = [];
this.Groups.myFunction = function(){alert(this.length);
};
this.Errors = [];
}
var selector = new Selector();
selector.Groups = [1,2,3];
selector.Groups.myFunction();
But when i set Group property i get error for calling method:
Error: selector.Groups.myFunction is not a function
I prefer to find a way using prototype object.
Thanks.