Forked from baybatu/attach-listener-to-push-method.js
Created
January 16, 2021 18:25
-
-
Save LCHCAPITALHUMAIN/450d4c198ee2aa8389d58826572af227 to your computer and use it in GitHub Desktop.
Attach event listener to Array push method call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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