Value lookup rules for JavaScript objects:
- The object itself
- The prototype of the object constructor
- The prototype constructor of the object constructor is prototype in such a way that it is searched along the prototype chain until the prototype of object
- Not found in the entire search chain. Returns undefine
- Returns the found value once found in the lookup process
1Object.prototype.foo = ' Bar ';2 3 functionpeople () {}4People.prototype.kind = ' People ';5 6 functionChinese () {}7Chinese.prototype =Newpeople ();8Chinese.prototype.constructor =Chinese;9Chinese.prototype.country = ' China ';TenChinese.prototype.name = ' Chinese '; One A varZhangsan =NewChinese (); -Zhangsan.name = ' Zhang San '; - theConsole.log (Zhangsan.name);//Zhang San, from Zhangsan object,[)--the setting of name in chinese.prototype is not searched -Console.log (Zhangsan.country);//China , from Chinese ' s prototype -Console.log (Zhangsan.kind);//people, from person ' s prototype -Console.log (Zhangsan.foo);//bar, from Object ' s prototype +Console.log (Zhangsan.age);//undefine
Value lookup for JavaScript objects