Last active
June 6, 2017 06:16
-
-
Save edwardwbli/9ced31795e3c7d06a57dfc3217da52f8 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
const arrayProto = Array.prototype; | |
const arrayMethods = Object.create(arrayProto); | |
const newArrProto = []; | |
['push','pop','shift','unshift','splice','sort','reverse'].forEach(function (method) { | |
let original = arrayMethods[method]; | |
newArrProto[method] = function mutator() { | |
console.log('listener working!'); | |
return original.apply(this,arguments); | |
} | |
}) | |
let list = [1,2]; | |
list.__proto__ = newArrProto; | |
list.push(3); | |
let list2 = [1,2]; | |
list2.push(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment