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 types of pointing problems

1. In function call mode this point window. As in the title obj.getX() It returns an immediate function , And the caller of this function is window

2. Method call mode this Point to the calling object . As in the question obj.getY()

3. Constructor call pattern ,this point new Who came out , That is, the instance object .
function A(){this.name="yy1"} var a = new A(); console.log(a.name)
4. Context call mode , Can be specified this Scope of . When the first parameter is null perhaps undefined Time ,this point window.

apply() and call()

fn.apply( Scope ,[...args])

fn.call( Scope ,arg1,arg2,arg3...)
function Woman(name){ this.name=name; } function Man(name){ this.name="yy1";
} Object.defineProperty(Woman,"name",{
configurable:true,// Can it be used delete, Can attribute properties be changed , Or can the accessor properties be modified ,,false Can not be redefined , The default value is true
enumerable:false,// Whether the object property can be passed through for-in loop ,flase Is not recyclable , The default value is true
//writable:false, Is the object property modifiable ,flase Is not modifiable , The default value is true //value:'njso'
The default value of the object property , The default value is undefined set:function() { name="yy2"; }, get:function(){ return
"yy3" } }) Woman.prototype = new Man(); var a = new Woman(); var b = new Man();
console.log(Woman.name)//yy3, obtain Woman Static properties of , Called get method
console.log(a.name)//undefined, Because I didn't give it this.name assignment , // If the note this.name = name
; Return to yy1. // When accessing properties and methods with dot syntax , It first looks inside 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 will Undefined, Methods will report errors .
console.log(b.name)//yy1, Construction method pattern ,this Point to instance object
be careful : Point syntax assignment , If the object does not have this property , This property is added to the object and assigned a value , If there is a property, the property value is modified , It doesn't change what's in the prototype .