Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Attach event listener to Array push method call
var eventify = function(arr, callback) {
arr.push = function(e) {
Array.prototype.push.call(arr, e);
callback(arr);
};
};
var array = [1,2,3];
eventify(array, function(newArray) {
alert("new array length is:" + newArray.length);
});
array.push(4); // alerts new array length is: 4
array.push(5); // alerts new array length is: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.