Javascript new array prototype in new object constructor
Javascript new array prototype in new object constructor 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 . Array test 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 ) z.test "test" z.t() "hello" Array.test Array.t 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. ...