var x = 3; var y = 4; var obj = { x: 1, y: 6, getX: function() { var x =5;
return function() { return this.x; }(); }, getY: function() { var y =7; return
this.y; } } console.log(obj.getX())//3 console.log(obj.getY())//6
this There are four kinds of directional problems

1. In function call modethis pointwindow. As in the titleobj.getX() An immediate function is returned, And the caller of this function iswindow

2. In method call modethis Point to calling object. As in the titleobj.getY()

3. Constructor call mode,this pointnew Objects coming out, That is, instance object.
function A(){"yy1"} var a = new A(); console.log(
4. Context calling mode, May specifythis Scope of action. When the first parameter isnull perhapsundefined Time,this pointwindow.

apply() andcall()

fn.apply( Scope of action,[...args]) Scope of action,arg1,arg2,arg3...)
function Woman(name){; } function Man(name){"yy1";
} Object.defineProperty(Woman,"name",{
configurable:true,// Can it be used?delete, Whether the property characteristics need to be changed, Or can access properties be modified,,false Not redefined, The default value istrue
enumerable:false,// Whether object properties can passfor-in loop,flase Is not recyclable, The default value istrue
//writable:false, Whether object properties can be modified,flase Not modifiable, The default value istrue //value:'njso'
Default values for object properties, The default value isundefined set:function() { name="yy2"; }, get:function(){ return
"yy3" } }) Woman.prototype = new Man(); var a = new Woman(); var b = new Man();
console.log(, ObtainWoman Static properties of, Calledget Method
console.log(, Because I didn't give assignment, // If = name
; Then returnyy1. // When accessing properties and methods with point syntax, It will first search within the object itself, If you find it, just use it,
// If not, go to the prototype, If it's not in the prototype, the property willUndefined, Method will report error.
console.log(, Construction method pattern,this Point to instance object
Be careful: Point syntax assignment, If the object does not have this property, This property will be added to the object and assigned, If there is such a property, it is to modify the property value, It doesn't change what's in the prototype.