は、これらのコードObject.create()メソッドとtoString()
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
Person.prototype = {
toString: function() { return this.firstName + ' ' + this.lastName; }
};
var test4 = Object.create(Person);
test4.firstName = "Phat4";
test4.lastName = "Wang4";
console.log(test4.toString === Object.toString); // true
console.log(test4.toString === Function.toString); // true
var test5 = { firstName: "Phat5", lastName: "Wang5" };
console.log(test5.toString === test4.toString); // false
console.log(test4.toString === Function.toString); // true
console.log(test5.toString === Object.prototype.toString); // true
console.log(test5.toString()); // [object Object]
console.log(test4.toString()); // Function.prototype.toString called on incompatible object
を考えると?それはtest4.toString
がtest5.toString
のようではないことを示していますが、私はそれを取得しません..
Ps。私はスレッドを検索しようとしたが、まだ自分自身に答えることはできません。これがanyと重複していれば、申し訳ありません。
Node.jsの機能ですか?またはブラウザで? – chakrit