Tag:prototype

  • Basic usage and creation method of JavaScript object

    Time:2022-5-1

    Object basic usage An object is a collection of related data and methods (usually composed of some variables and functions, which we call attributes and methods in an object) Object declaration method: let obj = { name: “Troy”, age: 18 }; let obj2 = new Object({ identity: “your dad” }); The above two are the […]

  • The specific execution process of new operation

    Time:2022-4-26

    1) Create an empty object2) Put this empty objectprotoPrototype pointing to constructor3) Assign this empty object to this4) Execute the code in the constructor. Note that this points to the new object, this N = 9999 is equivalent to B.N = 9999; Case: var A={n:4399}; var B=function () { this.n=9999; }; var C=function(){ var n=8888 […]

  • Closure of JavaScript function

    Time:2022-4-23

    What is closure Closures are the difficulty of JavaScript. Closures are also caused by the characteristics of function scope. The content of function scope can be reviewed in the previous articleScope of JavaScript function。 What is a closure? The explanation of closures in many documents is also very abstract, such as quoting Mozilla’s explanation of […]

  • Prototype prototype pattern

    Time:2022-4-13

    >>Return to c# common design mode 1. Introduction 2. Examples 3. Advantages and disadvantages 3.1. advantage 3.2. shortcoming 3.3. Applicable environment of prototype mode 1. Introduction definition Use the prototype instance to specify the type of object to be created, andCopy this prototypeTo create a new object. Usage scenario Frequently create “complex objects” Note that […]

  • Handwritten deep copy code

    Time:2022-4-11

    const obj1 = { age: 18, Name: ‘Qi Jing’, address: { city: ‘beijing’ }, arr = [1, 2, 3] } const obj2 = deepClone(obj1) obj2.address.city = ‘chengdu’ console.log(obj1.address.city) //Deep copy function deepClone(obj = {}) { if(typeof obj != ‘object’ || typeof obj ==null) { //If obj is not an array or object, or obj is […]

  • What is a prototype?

    Time:2022-3-20

    Prototype is the product of conforming to human natural thinking. There is an idiom in Chinese called “painting a tiger after a cat”. The cat here looks like the prototype of a tiger. Therefore, we can see that the method of using a prototype to describe an object has existed since ancient times. In different […]

  • Prototype chain and inheritance of prototype chain

    Time:2022-3-17

    Let’s talk about the inheritance of prototype chain and prototype chain All ordinary [[prototype]] chains will eventually point to the built-in object Prototype, which contains many common functions in JavaScript Why can we create a “class” with the help of a special attribute: by default, all functions will have a common and non enumerable attribute […]

  • Micro Vue framework implementation part2 — data agent implementation

    Time:2022-3-16

    Micro Vue framework construction Part1 — basic directory structureMicro Vue framework construction part3 – $mount method implementationMicro Vue framework construction Part4 – before render summary useObject.defineProperty()Implement data proxy Overview of data broker implementation principle Representative data model Object nested object Array type data model, and the proxy data will be changed after the array built-in […]

  • JS prototype and prototype chain

    Time:2022-3-14

    1、 Prototype and__ proto__       First remember two sentences:       ➀ each object has one__ proto__ Property and points to his prototype object. ➁ each constructor has a prototype object, and the constructor of the prototype object is equal to the constructor itself. var Person = function(name,age) { this.name = name; […]

  • About JS prototype syntax

    Time:2022-3-13

    Prototype grammar function Student(name,id){ this.name = name; this.id = id; } //Gets the prototype of the object Student.prototype.type = “student”; Student.prototype.message = function(){ console.log(this.name + “,” + this.id); }; //Generate instance object var student1 = new Student(“li”,111); Directly use an object literal to assign a value to the prototype object Student.prototype = { type : […]

  • Prototype mode (IV)

    Time:2022-3-11

    Basic introduction Prototype pattern refers to specifying the type of objects to be created with prototype instances, and creating new objects by copying these prototypes. Prototype pattern is a kind of creative design pattern, which allows one object to create another customizable object without knowing the details of creation The working principle is: by passing […]

  • JS prototype explanation

    Time:2022-3-8

    There is no doubt that the prototype in JS is a difficulty. It’s easy to faint if you don’t study deeply! Any JS knowledge point, such as event flow, closure, inheritance, etc., has many statements. For these knowledge points, we should first skillfully use them, and then sort out a set of our own understanding […]