【发布时间】:2017-04-27 00:55:23
【问题描述】:
var People = function()
{
this.FirstName = "John";
this.LastName = "Doer";
}
var Employee = function(o)
{
this.DateHired = "June 30";
this.prototype = o;
}
var obj = new People();
var employee1 = new Employee(obj);
print(employee1.DateHired);
print(employee1.FirstName);
输出: 6 月 30 日
我预计输出应该是: 6月30日 乔恩
但这不是我所期望的。那么有人可以解释一下上面的代码有什么问题吗?
【问题讨论】:
-
您的
print()与javacript标签有何关联?更正您的问题 -
应该是
console.log,可能是.. -
我正在使用 js 交互式控制台,所以 print() 可以工作。
-
@T.J.Crowder 我的目的不是为了上课。我试图从我从书中读到的一段代码中了解原型连接是如何工作的: if (typeof Object.beget !== 'function') { Object.beget = function (o) { var F = function ( ) {}; F.prototype = o;返回新的 F(); }; } var another_stooge = Object.beget(stooge);上面的代码工作。
标签: javascript