- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如果我有一个名为 Person 的类。
var Person = function(fname, lname){
this.fname = fname;
this.lname = lname;
}
Person.prototype.mname = "Test";
var p = new Person('Alice','Bob');
现在,p.__proto__
指的是 Person 的原型(prototype),但是当我尝试执行 Person.__proto__
时,它指向 function()
,并且 Person.constructor
指向 Function()
。
谁能解释一下 function()
和 Function()
之间的区别以及为什么 Function()
类的原型(prototype)是一个 function()
?
最佳答案
Can someone explain what is the difference between function() and Function() and why the prototype of a Function() class is a function()?
__proto__
是公开 [[prototype]] 的实现细节。 [[prototype]] 和构造函数不需要(通常不是)相同的东西。无论如何...
考虑这个假设:这是一个暗示。取决于引擎的细节——在测试的特定引擎中(FF,哪个版本?),Function 是一个对象,它本身有一个 [[prototype]] 函数。 function 是原始函数对象。 Person.prototype(默认情况下)是函数类型(原始函数对象),断言是这种明显二分法的结果。 (JS 有一些怪癖:new Number(0)
与 0
不同。)
但是,在 IE(8) 中情况并非如此。在 IE 中,默认原型(prototype)是“普通对象”,而不是函数对象。
关于javascript - 函数的__proto__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2872257/
我的理解是 Object.__proto__ 是 javascript 中的“顶级”原型(prototype)对象。我希望它的 __proto__ 为空,但在谷歌浏览器中(没有尝试过其他浏览器),它不
为什么 Object.__proto__ === Function.__proto__ 在 JavaScript 中? 这样设计的目的是什么? 最佳答案 __proto__ property对象的原型
我一直在研究 prototype chain在 Javascript 中,这个主题让我想知道...是否有一个通用名称或术语来指代原型(prototype)链末尾的所有其他对象? 我正在 GitHub
似乎在 JavaScript (ES6) 类中 super.__proto__ === this.__proto__ . 您能解释一下为什么会出现这种情况吗?该行为在不同浏览器中似乎是一致的,因此我怀
为什么如果F - 简单函数: F.prototype !== F.__proto__ 但是 Function.prototype === Function.__proto__ ? 最佳答案 F.pro
obj.prototype.__proto__ = events.EventEmitter.prototype 我有时会看到上面的代码,我用谷歌搜索了一下,他们说这一行将所有 EventEmitter
曾经能够毫无问题地做到这一点: for (data in dataArray) { // do some stuff }; 现在,它突然迭代这个 __proto__添加到我的 dataArray 的数
我正在阅读 __proto__ 和 prototype 对象之间的区别,但是当我尝试访问 __proto__ 的实例时一个对象,它返回给我 undefined。 下面是我写的代码: function
当一个对象被实例化时,无论是字符串/函数/等等,__proto__属性(property)包括在内。该属性似乎是由 __proto__ 生成的Object.prototype 中的访问器... Obj
__proto__ 已弃用。为什么像谷歌浏览器这样的大型浏览器仍在使用它?有没有计划倾倒它? 最佳答案 在语言/框架中最难做的事情之一实际上是删除已弃用的功能。世界上仍然有大量代码依赖于此功能。删除它
function makeAdder(x) { return function(y) { return x + y; }; } var add5 = makeAdder(5); add
我正在重新从头开始学习 JavaScript/做个人笔记,并遇到了一些我想要一些解释的东西。 谁能解释一下: Object.prototype.hasOwnProperty("__proto__");
下面是一些示例,展示了基于对象定义和创建方式的原型(prototype)继承的不同行为。我区分对象的“原型(prototype)属性”,例如someObject.prototype 和“原型(prot
我正在尝试使用带有继承的揭示模块模式。我似乎让它工作正常,但它使用“__proto__”,我知道它被认为已被弃用。有没有更好的方法来创建继承而不使用“__proto__”? var Person =
函数getBooks已在Author.prototype中定义。但它不能在 Author 对象中使用。当我使用 __proto__ 继承 Person 属性时。为什么Author对象没有getBook
我有这个功能: 函数 Foo(){} 根据这张图片: >> Foo.prototype -> Foo {} 所以如果我写: Foo.prototype.constructor 现在 - 它引
什么时候 __proto__ 有用? 很多浏览器都支持它,但由于不是所有浏览器都支持,所以程序员似乎害怕使用它。我从未在任何代码中看到它(例如库 jQuery 和 backbone.js)。 什么时候
当我创建一个空白对象时: var o = {}; 为什么新建对象时看不到'__proto __'对象,但添加函数时可以? 编辑:为了完整起见,要创建一个真正的空白对象(没有原型(prototype)链
Object.each , Object.keys , ... 当我尝试与作为类属性的对象一起使用时无法正常工作,请检查 this example : var map = {a: 1, b: []};
在 __proto__ 周围使用方括号时在一个对象中,__proto__是可枚举的。未提供方括号时,__proto__是不可枚举的。 例子: obj = {"__proto__": "Hello"}
我是一名优秀的程序员,十分优秀!