How to bind function to an object in JavaScript

1 Answer

0 votes
const worker = {
    name: "Tom",
    print() {
        console.log(this);
    }
}

const print = worker.print.bind(worker);

print();



 
/*
run:
      
{ name: 'Tom', print: [Function: print] }
 
*/

 



answered Mar 29, 2020 by avibootz

Related questions

4 answers 279 views
1 answer 118 views
118 views asked Feb 6, 2020 by avibootz
1 answer 148 views
1 answer 130 views
1 answer 113 views
...