This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// __proto__ | |
var array= [1,2,3] | |
array.push(4) //哪里来的这个方法? | |
//当访问对象其中的一个成员或方法的时候,如果这个对象中没有这个方法或成员, | |
//那么Javascript引擎将会访问这个对象的__proto__成员所指向的另外的一个对象,并在那个对象中查找指定的方法或成员, | |
//如果不能找到,那就会继续通过那个对象的__proto__成员指向的对象进行递归查找,直到这个链表结束 | |
//有点像 Ruby 中得方法查找 | |
//因为 chrome 中访问不到 __proto__ 这个属性 | |
[] instanceof Array // => true | |
Object.getOwnPropertyNames(Array) //=> ["length", "name", "arguments", "caller", "prototype", "isArray", "observe", "unobserve"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this | |
//1、this 是调用当前可执行代码的对象的引用 | |
//2、this 是与 Scope 有关系的一个特殊对象。 | |
//3、JavaScript 引擎会自动初始化、更新、维持 this,且无法手动修改 this 的值(直接用就可以)。 | |
//4、PS: this 的值就是我们所说的 Context(上下文) | |
this //=> window | |
window.name = "window" // 等价于在 global 中直接定义变量 var name = 'window' | |
function getName(){ | |
return this.name; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var duan = { | |
name: 'duan', | |
email: 'duan@easya.cc' | |
}; | |
//查看对象所有的的属性名称 | |
Object.getOwnPropertyNames //=> ["name", "email"] | |
//查看对象属性的配置 | |
Object.getOwnPropertyDescriptor(duan, 'name') //=> Object {value: "duan", writable: true, enumerable: true, configurable: true} 这个是什么? |