[英]Why hasOwnProperty returns false on a constructor function but string property returns true when accessed without instantiating the function
I basically understand, hasOwnProperty method in JavaScript is used to check whether the object has the specified property as its own property.我基本明白了,JavaScript 中的hasOwnProperty方法是用来检查对象是否有指定的属性作为自己的属性。
But the behaviour I checked in browser console below got me downright confused.但是我在下面的浏览器控制台中检查的行为让我非常困惑。 Can someone explain me why this is happening.
有人可以解释我为什么会这样。 I did try finding existing answer, but couldnt find a relevant link.
我确实尝试找到现有答案,但找不到相关链接。
If you check the typeof Shape it will return you a "function" but typeof s will return "object"如果您检查 typeof Shape 它将返回一个“函数”但 typeof s 将返回“对象”
When you call var s = new Shape();当你调用 var s = new Shape(); Shape will considered as class but name and size are members of Shabe class.
Shape 将被视为类,但名称和大小是 Shabe 类的成员。
Default constructor will called on new Shape() and creates a object of Shape.默认构造函数将调用 new Shape() 并创建一个 Shape 对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.