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 303 views
1 answer 128 views
128 views asked Feb 6, 2020 by avibootz
1 answer 160 views
1 answer 141 views
1 answer 126 views
...