I have array and I want to customize some of his prototype's methods. If i use:
arr.push = function(){
doSomething()
Array.prototype.push.call(arguments);
}
I'm creating own property push for arr. But I want to make new array-like object that will have prototype with method push from last example. I've tried to make such thing:
// creating new object which prototype linked to _Array.prototype
var newArr = new (function _Array(){});
// setting up method
_Array.prototype.push = function(){...}
// copying all data
arr.forEach(function(val, index){
newArr[index] = val;
});
newArr.length = arr.length
//updating original array
arr = Array.prototype.slice.call(newArr);
Yes, after that I will got array-like object, but Array.prototype.slice returns object binded with Array prototype not created by me _Array.prototype.
So can I create array with custom prototype?