无法理解这个原型概念
Not able to understand this prototype concept
我正在浏览 article` 时遇到了这段代码,
它在哪里解释原型及其工作原理。
我要的是,这句话相对于代码是什么意思。
This code creates a Date object, then walks up the prototype chain, logging the prototypes. It shows us that the prototype of myDate is a Date.prototype object, and the prototype of that is Object.prototype
const myDate = new Date();
let object = myDate;
do {
object = Object.getPrototypeOf(object);
console.log(object);
} while (object);
其实很简单:
const myDate = new Date(); // Create a Date object.
let object = myDate;
do {
object = Object.getPrototypeOf(object); // Find the object’s prototype.
console.log(object); // Print to the log.
} while (object); // Repeat (finding prototypes’ prototypes)
// as long as there are prototypes to be found.
所以,我们会发现对象的原型也有一个原型。这就是摘录中提到的链条。
我正在浏览 article` 时遇到了这段代码, 它在哪里解释原型及其工作原理。 我要的是,这句话相对于代码是什么意思。
This code creates a Date object, then walks up the prototype chain, logging the prototypes. It shows us that the prototype of myDate is a Date.prototype object, and the prototype of that is Object.prototype
const myDate = new Date();
let object = myDate;
do {
object = Object.getPrototypeOf(object);
console.log(object);
} while (object);
其实很简单:
const myDate = new Date(); // Create a Date object.
let object = myDate;
do {
object = Object.getPrototypeOf(object); // Find the object’s prototype.
console.log(object); // Print to the log.
} while (object); // Repeat (finding prototypes’ prototypes)
// as long as there are prototypes to be found.
所以,我们会发现对象的原型也有一个原型。这就是摘录中提到的链条。