[英]Set function prototype to null has no effect to newly created javascript object
[英]Pushing newly created whole object to array with prototype function
我试图在我的对象的构造上运行一个函数,该函数将整个对象传递给一个函数,然后将其推入数组。
我可以一次传递一个属性:
function Item(title, description, price) {
'use strict';
this.title = title;
this.description = description;
this.getPrice = function (price) {
var pricestring = "£";
pricestring = pricestring + price;
return pricestring;
};
this.addToPage(this.title, this.description);
}
但是我希望能够像这样传递整个对象:
this.addToPage(this.Item);
但是它总是返回undefined。
我的addToPage是函数是这样的:
Item.prototype.addToPage = function (item) {
'use strict';
constructedItems.push(item);
};
实际上有可能从对象内部传递整个对象吗? 还是我可以使用另一种技术?
您正在寻找this
,它是指正在构造的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.