Guest User

Untitled

a guest
Jan 15th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. Function.prototype.myOwnCall = function(context) {
  2. // global -> window for node.js
  3. context = Objesct.assign({}, someOtherThis) || global;
  4. var uniqueID = "00" + Math.random();
  5.  
  6. while (context.hasOwnProperty(uniqueID)) {
  7. uniqueID = "00" + Math.random();
  8. }
  9.  
  10. context[uniqueID] = this;
  11. const args = [];
  12.  
  13. // staret from second parameter to dont takein count context
  14. for (var i = 1, len = arguments.length; i < len; i++) {
  15. args.push("arguments[" + i + "]");
  16. }
  17.  
  18. // strings are reparsed into statements in the eval method
  19. // Here args automatically calls the Array.toString() method.
  20. var result = eval("someOtherThis[uniqueID](" + args + ")");
  21.  
  22. return result;
  23. };
  24.  
  25. let testLog = function(a, b) {
  26. console.log(this.name + ' ' + a + ' ' + b);
  27. };
  28.  
  29. let testObj = {
  30. name: 'John'
  31. }
  32.  
  33. testLog.myOwnCall(testObj, 'Good', 'Guy')
Add Comment
Please, Sign In to add comment