1. Prototype The prototype is a property under
By adding properties to the prototype, all instantiated objects can share properties and methods Car.prototype = { height : 1400, lang : 4900, carName : 'BMW' } function Car() { } var car = new Car(); 2. Prototype chain Each instance object has a
2.1 Constructor
function Star(uname, age) { this.uname = uname; this.age = age; } // In many cases, we need to manually use the constructor property to point back to the original constructor Star.prototype = { // If we modify the original prototype object and assign an object to the prototype object, we must manually use constructor to point back to the original constructor constructor: Star, // Manually set to point back to the original constructor sing: function() { console.log('I can sing'); }, movie: function() { console.log('I can act in movies'); } } var zxy = new Star('Jacky Cheung', 19); console.log(zxy) When modifying the function prototype, because 2.2 call/apply By using Difference: function Person(name,age,sex) { this.name = name; this.age = age; this.sex = sex; } function Student(name,age,sex,tel,grade) { //var this = {name: "lin", age: "19", sex: "male", tel: 123, grade: 78} Person.call(this,name,age,sex);//Change this to point to this function through call//Person.apply(this,[name,age,sex]) this.tel = tel; this.grade = grade; } var student = new Student('lin','19','male',123,78); 2.3 new()
var obj = {} //Create an empty object obj.__proto__ = Person.prototype; //Inherited scope Person.call(obj,) //Change this pointer //These three steps are implicit var person = new Person(); //new operation This is the end of this article about the details of the difference between prototype and prototype chain prototype and proto. For more relevant content about the difference between prototype and prototype chain prototype and proto, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL cleverly uses sum, case and when to optimize statistical queries
>>: HTML dl, dt, dd tags to create a table vs. Table creation table
This article shares with you the detailed install...
Table of contents 1. The simplest example 2. Cust...
Use vite to build a vue3 project You can quickly ...
Table of contents Basic usage of Promise: 1. Crea...
Just like this effect, the method is also very si...
Nginx uses a fixed number of multi-process models...
Get the current date + time (date + time) functio...
I encountered this problem today. I reassigned the...
Based on theories such as Saussure's philosop...
Anti-shake: Prevent repeated clicks from triggeri...
Recently, https has been enabled on the mobile ph...
Table of contents 1. Document.execCommand() metho...
cause The way to import external files into a min...
Table of contents vue router 1. Understand the co...
Table of contents Preface Background Implementati...