Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function.prototype.myOwnCall = function(context) {
- // global -> window for node.js
- context = Objesct.assign({}, someOtherThis) || global;
- var uniqueID = "00" + Math.random();
- while (context.hasOwnProperty(uniqueID)) {
- uniqueID = "00" + Math.random();
- }
- context[uniqueID] = this;
- const args = [];
- // staret from second parameter to dont takein count context
- for (var i = 1, len = arguments.length; i < len; i++) {
- args.push("arguments[" + i + "]");
- }
- // strings are reparsed into statements in the eval method
- // Here args automatically calls the Array.toString() method.
- var result = eval("someOtherThis[uniqueID](" + args + ")");
- return result;
- };
- let testLog = function(a, b) {
- console.log(this.name + ' ' + a + ' ' + b);
- };
- let testObj = {
- name: 'John'
- }
- testLog.myOwnCall(testObj, 'Good', 'Guy')
Add Comment
Please, Sign In to add comment