Use jQuery to quickly and efficiently create web page interaction effects


1. Create an object
(1) Custom object
   syntax: var object name=new Object();
(2) Built-in object
   String (string) object.
   Date (object) object
   Array (array) object
   Bollean (logical) object
   Math ( Arithmetic) object
   RegExp object
// example
function an(name, pwd) {
  this.name=name;
  this.pwd=pwd;
  this.show=function () {
      alert("Username:"+this.name+"\nPassword:"+this.pwd);
   }
}
var an=new an("name","123");
   an.show();
2. Constructor
(1) Step:
   Create a new object
   and assign the scope of the constructor to the new object (this points to the new object)
   Execute the code in the constructor
   to return the new object
(2) Notes:
   1. Construction Function, the first letter should be capitalized
   2. The code should pay attention to the order
    Man.prototype=new Humans(); //Inherit the
  method
    Man.prototype.getHead=function(){
     return this.head;
  }
3. Inherit the property
   a.call(b Attributes, parameters); b object is replaced with a
4. Prototype object
(1) Prototype: When the constructor is created, the system will create and associate an empty object for the constructor by default, this object is the prototype
(2) Prototype Access form:
  1. Constructor.prototype 2.Object
  .__proto__ Non-standard properties, there are compatibility issues
(3) How to use prototypes
   1. Use dynamic characteristics to add properties and methods to prototype objects
   2. Directly replace prototype objects
5. Prototype chain
Every object has a prototype, every prototype is an object, and every prototype also has a prototype, forming a chain structure, which is called a prototype chain
(1) The borrowed constructor is the inner part of the subtype constructor through apply() Or call() method calls the constructor of the type
(2) The idea of ​​combined inheritance is to use the prototype chain to realize the inheritance of prototype properties and methods

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324707426&siteId=291194637