Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Bonsai Trees

Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,759 questions

12,132 answers

573 users

How to use apply in JavaScript

1 Answer

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 />');
};

var workerSalary = function(salary)
{
    document.write(this.name + ' salary: $' + salary + '<br />');
};

var updateDetails = function(name, age, from)
{
    this.name = name;
    this.age = age;
    this.from = from;
};


var run = function(worker, method, args)
{
    method.apply(worker, args);
};


run(worker1, workerDetails);
run(worker1, workerSalary, [13873]);

run(worker1, updateDetails, ['Holly', 33, 'CA']);
run(worker1, workerDetails);


/*
run:
  
Holly 33 NY
Holly salary: $13873
Holly 33 CA
    
*/

 




answered Jul 27, 2015 by avibootz
...