Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Maria Dan
Added: May 25, 2021 4:27 PM
Modified: May 27, 2021 4:03 PM
Views: 338
Tags: no tags
  1. obj.func.bind(context)(param1, param2)
  2. obj.func.apply(context, [param1, param2])
  3. obj.func.call(context, param1, param2)
  4. // call сразу вызывает метод, bind - нет
  5.  
  6. let obj = {
  7.   pr: 1,
  8.   pr2: 2,
  9.   m: () => 1
  10. }
  11.  
  12. function foo () {
  13.   console.log(this.pr)
  14. }
  15.  
  16. foo.bind(obj)()
  17.  
  18. let obj = {
  19.   name: "test",
  20.   sayHi (){
  21.     let a = function () {
  22.       return this.name;
  23.     }.bind(this)
  24.     return a();
  25.   }
  26. }
  27.  
  28.