1, object method call pattern method internal this point to the object of the current caller D
Defining classes (constructors)
function Dog (dogname) {
Create an empty object to let the empty object ==this
THIS.name = Dogname;
this.age = 0;
This.run = function () {
Console.log (THIS.name + ' is running ... ')
}
This is returned by default if the function calls (new) as a constructor and no data is returned.
}
var d= new Dog (' Wangwang ');
D.run ();
2. Constructor call mode new
function Cat () {
THIS.name = "Cat"
This.age = 19;
This.run = function () {
Console.log (THIS.name + ' is running ... ')
}
}
var cat = new Cat (); Constructor call pattern
Cat.run ()//method invocation mode
3. Function call mode
function f (A, B) {
Console.log (A + ' +b)
Console.log (this) window
}
F (2,3)
Exercises
function Dog () {
This.age = 19;
Console.log (This)
}
Dog ()//window function call pattern
var d = new Dog (); D Constructor Call pattern
4.
Four invocation modes of JS advanced-function