Skip to content

Instantly share code, notes, and snippets.

@edwardwbli
Last active June 6, 2017 06:16
Show Gist options
  • Save edwardwbli/9ced31795e3c7d06a57dfc3217da52f8 to your computer and use it in GitHub Desktop.
Save edwardwbli/9ced31795e3c7d06a57dfc3217da52f8 to your computer and use it in GitHub Desktop.
'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