var singleton = (function () { var data, method_args; data = []; method_args = []; function add (items) { var i; data.push(items); method_args.push(arguments); } function remove () { data.pop(); method_args.push(arguments); } return { add : add, remove : remove } }());
var original_push, data; // original_push = Array.prototype.push; // Array.prototype.push = function () { // data = this; }; // singleton.add(); // Array.prototype.push = original_push; // console.log(data);
var original_push, fake_method_calls, data; // original_push = Array.prototype.push; // fake_method_calls = 0; // Array.prototype.push = function () { // this if (fake_method_calls === 0) { data = this; } fake_method_calls += 1; // return original_push.apply(this, arguments); } // singleton.add(); // Array.prototype.push = original_push; // console.log(data);
Source: https://habr.com/ru/post/143288/
All Articles