function Ctor() {}
const inst = new Ctor();
console.log(Object.getPrototypeOf(inst) === Ctor.prototype); // trueFunction: prototype / notebook
Function: prototype
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
async function* asyncGeneratorFunction() {}
function* generatorFunction() {}const method = { foo() {} }.foo;
const arrowFunction = () => {};
async function asyncFunction() {}class Class {}
function fn() {}const boundFunction = function () {}.bind(null);function Ctor() {}
Ctor.prototype = 3;
console.log(Object.getPrototypeOf(new Ctor()) === Object.prototype); // truefunction Ctor() {}
const p1 = new Ctor();
const p2 = new Ctor();
Ctor.prototype.prop = 1;
console.log(p1.prop); // 1
console.log(p2.prop); // 1class Dog {
constructor(name) {
this.name = name;
}
}
Dog.prototype.species = "dog";
console.log(new Dog("Jack").species); // "dog"class Dog {
static {
Dog.prototype.species = "dog";
}
constructor(name) {
this.name = name;
}
}
console.log(new Dog("Jack").species); // "dog"