Tag:create object

  • 06. Object advanced – object creation mode


    01. Object constructor mode Method 1: object constructor mode*Routine: create an empty object object first, and then add properties / methods dynamically*Applicable scenario: uncertain internal data of objects at the beginning*Problem: too many statements //A person: Name: “Tom”, age: 12 var p = new Object() p = {} p.name = ‘Tom’ p.age = 12 p.setName […]

  • Common object creation modes


    1. Object constructor var obj = new Object(); obj.name = ‘tom’; obj.age = 15; obj.sayName = function() { console.log(this.name) } The disadvantage of this method is obvious, that is to write a lot of code. 2. Object literal creation var obj1 = { name: ‘tom’, age: 15, sayName: function() { console.log(this.name) } } var obj2 […]

  • Effective Java 3rd Edition (1) – Replacing constructors with static factories


    This article is the first in the Effective Java series, so it is necessary to outline the characteristics of this book. Of course, many people may have read it. After all, it is famous for one of the four famous Java works, but there will always be new ones, such as me! The third edition […]