다음 코드 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
마지막 줄 console.log(test4.toString())
이 오류가 발생 이유는 무엇
test4.toString
가
test5.toString
과 같지 않다는 것을 보여줍니다. 그러나 나는 그것을 얻지 못합니다 ..
Ps. 스레드 검색을 시도했지만 여전히 대답 할 수 없습니다. 죄송합니다. 대신이의
Node.js를 인 목적? 또는 브라우저에서? – chakrit