Если я сделаю:
Array.prototype.test = "test"
Array.prototype.t = function() {return "hello"}
Каждый новый Array
будет иметь свойство test
и метод t
.
Как я могу сделать то же самое, не затрагивая все массивы?
Как:
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"])
Так что z.test
вернет "test"
и z.t()
вернет "hello"
?
(но Array.test
и Array.t
останутся undefined
)
Я лучше объясню:
Array.prototype.t="test";
Array.prototype.test = function(){ return "hello";}
z=new Array("john", "andrew")
console.log(z);
Но это влияет на ВСЕ массивы.
Я хочу то же самое, но с новым конструктором Names, который наследует конструктор Array.