Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,026 questions

51,982 answers

573 users

How to use call in JavaScript

2 Answers

0 votes
var worker1 = {name: 'Holly', age: 33, from: 'NY'};
var worker2 = {name: 'Molly', age: 31, from: 'LA'};

var workerDetails = function()
{
    document.write(this.name + ' ' + this.age + ' ' + this.from + '<br />');
};


workerDetails.call(worker1);
workerDetails.call(worker2);


/*
run:
  
Holly 33 NY
Molly 31 LA
    
*/

 



answered Jul 27, 2015 by avibootz
0 votes
document.write(this + '<br />'); // the object Window


var worker1 = {name: 'Holly', age: 33, from: 'NY'};
var worker2 = {name: 'Molly', age: 31, from: 'LA'};

var workerDetails = function()
{
    document.write(this.name + ' ' + this.age + ' ' + this.from + '<br />');
    document.write(this + "<br />"); // our object worker1 and worker2 
};


workerDetails.call(worker1);
workerDetails.call(worker2);


/*
run:
  
[object Window]
Holly 33 NY
[object Object]
Molly 31 LA
[object Object]
    
*/

 



answered Jul 27, 2015 by avibootz
...