Is possible create a clone of the object Array? I do not want to extend the Array object itself because my specific methods should not be exposed for all the arrays of my app. Only a specific Arrays.
var Arr = function () {};
Arr.prototype = Object.create( Array.prototype );
Arr.prototype.push = function() {
// Some custom code here
Array.prototype.push.apply( this, arguments );
};
This example work well using methods, but if I set the values literally, the length is not incremented. Because Arr is an Object actually.
var arr1 = new Arr();
arr1[1] = 13;
console.log(Object.prototype.toString.call( arr1 ), arr1, arr1.length); // [object Object] { '1': 13 } 0
var arr2 = new Array();
arr2[1] = 13;
console.log(Object.prototype.toString.call( arr2 ), arr2, arr2.length); // [object Array] [ , 13 ] 2