The constructor and prototype js advanced on the inside

1. Create a literal way

var obj = {};

2.new keyword

var obj=new Object();

3. The embodiment constructor

function Person(uname,age){

this.uname=uname;

this.age=age;

}

var obj = new Person ( 'Andy', '18 ');

4. constructor prototype prototype

function Star(uname, age) {    

 this.uname = uname;     this.age = age; }

Star.prototype.sing = function() {

console.log ( 'I can sing');}

var ldh = new Star ( 'Andy', 18);

var zxy = new Star ( 'Jacky', 19);

ldh.sing (); // I will sing

zxy.sing (); // I will sing

5. Inheritance

When (. 1) call () function can be called, this point may be modified using the call (), if the parameter is modified after this point

6. Several new methods

(1) forEach iterate

 arr.forEach(function(value, index, array) {      

  // First argument: array elements       

 // Second parameter: the index of the array elements      

  Third, // parameters: current array  

}) // for loop array traversal corresponds to no return value

(2) filtered array of filter

 was arr = [12, 66, 4, 88, 3, 7];  

 var newArr = arr.filter(function(value, index,array) {   

    // First argument: array elements     

    // Second parameter: the index of the array elements   

   Third, // parameters: current array     

 return value >= 20;  

 });   

console.log (newArr); // [66,88] // return value is an array of new

(3) an array of some methods

Find element in the array satisfies the condition

If there is satisfied a condition element, the loop is terminated immediately

 

Guess you like

Origin www.cnblogs.com/piyangtao/p/11455920.html