1
所有,如果我傳遞一個對象到Object.create
,這意味着創建一個新的對象從它繼承。下面的代碼證明了它。Object.create從一個對象
function Shape() {
this.x = 0;
this.y = 0;
}
Shape.prototype.move = function(x, y) {
this.x += x;
this.y += y;
console.info("Shape moved.");
};
Rectangle = Object.create(Shape);
Rectangle.__proto__==Shape;//it is true.yes, I can understand
Rectangle//It is Function {} I can not understand it.
Rectangle.constructor==Function//it is true.I can not understand it.
該圖表示關係如下。但是我不明白的是它的亮點部分。究竟是什麼Rectangle
?我的意思是什麼Function{}
,它來自哪裏?以及Rectangle.constructor
屬性,我不知道所有對象是否具有constructor
屬性,以及constructor
屬性用於什麼目的?謝謝。
PS:以上所有值都是在FireBug中計算和觀察的。
更正圖由MiniTech移動的評論
+1 - +2更多,當你添加一些關於構造函數的信息和它的作用;-) – 2013-04-25 02:21:40
@SeanVieira:哪個構造函數? '函數'或'矩形'或'矩形'的排序?「? :D – Ryan 2013-04-25 02:22:40
大家好,很抱歉再錯過一次'=',應該是'==',請再次查看。謝謝。 – 2013-04-25 02:24:11