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 488 views
1 answer 220 views
220 views asked Feb 6, 2020 by avibootz
1 answer 243 views
1 answer 224 views
1 answer 205 views
...