If I do:
Array.prototype.test = "test"
Array.prototype.t = function() {return "hello"}
Every new Array will have the property test and the method t.
How can I do the same without affecting all Arrays?
Like:
Names = function(arr){
// Contacts constructor must be the same of Array
// but add the property test and the function t
}
z=new Names(["john","andrew"])
So that z.test will return "test" and z.t() will return "hello"?
(but Array.test and Array.t would stay undefined)
I explain better:
Array.prototype.t="test";
Array.prototype.test = function(){ return "hello";}
z=new Array("john", "andrew")
console.log(z);
But this affects ALL arrays. I want the same but with a new constructor Names that inherits Array constructor.
// Contacts constructor must be the same of Array" this part is not clear. Do you meanNamesinstances should inheritArray.prototypeas well?