![](/img/trans.png)
[英]How can I get all new objects name created from a function constructor?
[英]How do i get the full name from this function constructor
我正在嘗試(並且慘遭失敗)使用我的函數構造函數中的函數來檢索manTwo的全名。 任何幫助將不勝感激。 鉭
function clenk(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
fullName: function () {
return this.firstName + " " + this.lastName;
}
}
var manTwo = new clenk("Mike","Tool");
manTwo.fullName();
更改
fullName: function () {
至
this.fullName = function () {
您還可以使用原型:
function clenk(arg1, arg2) {
this.firstName = arg1;
this.lastName = arg2;
}
clenk.prototype.fullName = function () {
return this.firstName + " " + this.lastName;
}
如果您創建了許多clenk
實例,這會更有效率(請注意,標准做法是對“類”的首字母使用大寫字母)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.