Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
var parentObj={
  name:"jeff",
  age:27,
  
  childObj:{
    childName:"tom",
    age:20,
    
    par:this,//
    par1:parentObj,
    
    getChildName:function(){
       console.log("this0=",this);
       console.log("par=",this.par);//拿到的是window对象(问题1:为什么子对象中的this是window,而不是父对象)
       console.log("par1=",this.par1);//拿不到父对象
       console.log("par2=",parentObj);//可以拿到父对象(问题2:为什么这边可以拿到父对象,而上边的parentObj赋给par1,this.par1却拿不到父对象)
       
       //console.log("parentName=",,",childName=",this.childName);
    },
    
  },
  
  init:function(){
     var self=this;
     self.childObj.getChildName();
  }
  
  
};
parentObj.init();
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers