How to use the JavaScript call?

Summarized in one sentence: call method is a function to call. Role is to change the properties of the environment. Around a bit, for example.

Here is the code variables and functions declared in the window environment.

var name = 'Wang Yanpeng';

var age = 18;

var exec = function()

{

  console.log(this.name);

  console.log(this.age);

}

were self property = {

  name : 'selftName',

  age: selfAge '

}

... One day, I want to perform exec method, let him selfProperty output of name and age.

So I wrote:

this.exex.call(selfProperty);

Output:

selftName
selfAge

Learning together, welcomed the exchange.

 

Guess you like

Origin www.cnblogs.com/pecool/p/12607359.html