Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中,proto在哪里声明?_Javascript_Prototype Programming - Fatal编程技术网

在Javascript中,proto在哪里声明?

在Javascript中,proto在哪里声明?,javascript,prototype-programming,Javascript,Prototype Programming,考虑这个例子: var a={} a、 b=5 a、 hasOwnProperty(“b”)//返回True a、 hasOwnProperty(“\uuuu proto\uuuu”)//返回False 如果\uuuu proto\uuuu本身没有声明为对象自己的属性,那么 此\uuuu proto\uuuu属性在哪里声明 如果该属性本身不是对象自己的属性,那么在原型链中搜索时如何引用该属性 \uuuu proto\uuuu属性属于对象。prototype在对象的prototype对象中声明,

考虑这个例子:

var a={}
a、 b=5
a、 hasOwnProperty(“b”)//返回True
a、 hasOwnProperty(“\uuuu proto\uuuu”)//返回False
如果
\uuuu proto\uuuu
本身没有声明为对象自己的属性,那么

  • \uuuu proto\uuuu
    属性在哪里声明
  • 如果该属性本身不是对象自己的属性,那么在原型链中搜索时如何引用该属性

  • \uuuu proto\uuuu
    属性属于
    对象。prototype
    对象的
    prototype
    对象中声明,并且不是代码中对象
    a
    的自有属性。这就是为什么当你这么做的时候它会返回false

    a.hasOwnProperty("__proto__") // returns False
    
    如果您这样做:

    console.log(Object.prototype.hasOwnProperty("__proto__")) // returns true
    
    这将返回
    true
    ,因为
    \uuuuu proto\uuuuu
    对象的自有属性。prototype


    console.log(Object.prototype.hasOwnProperty(“\uuu proto\uuu”))
    。那么我的第二个问题呢?