• 关于js高级里面的构造函数和原型


    1.字面量创建方式

    var obj={};

    2.new关键字

    var obj=new Object();

    3.构造函数的方式

    function Person(uname,age){

    this.uname=uname;

    this.age=age;

    }

    var obj=new Person('刘德华','18');

    4.构造函数原型prototype

    function Star(uname, age) {    

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

    Star.prototype.sing = function() {

    console.log('我会唱歌');      }

    var ldh = new Star('刘德华', 18);

    var zxy = new Star('张学友', 19);

    ldh.sing();//我会唱歌

    zxy.sing();//我会唱歌

    5.继承

    (1)call()可以调用函数 ,可以修改this的指向  使用call()的时候参数要是修改后this的指向

    6.新增的几种方法

    (1)遍历数组forEach

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

      //参数一是:数组元素       

     //参数二是:数组元素的索引      

      //参数三是:当前的数组  

    })   //相当于数组遍历的 for循环 没有返回值

    (2)过滤数组filter

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

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

        //参数一是:数组元素     

        //参数二是:数组元素的索引   

       //参数三是:当前的数组     

     return value >= 20;  

     });   

    console.log(newArr);//[66,88] //返回值是一个新数组

    (3)数组方法some

    查找数组中是否满足条件的元素

    如果有一个满足条件的元素,立马终止循环

  • 相关阅读:
    强连通分量 Tarjan
    【二叉搜索树】hdu 3791
    【二叉树】hdu 1622 Trees on the level
    【二叉树】hdu 1710 Binary Tree Traversals
    【leetcode】lower_bound
    【leetcode dp】629. K Inverse Pairs Array
    【leetcode最短路】818. Race Car
    【leetcode 字符串】466. Count The Repetitions
    【leetcode dp】132. Palindrome Partitioning II
    【leetcode dp】Dungeon Game
  • 原文地址:https://www.cnblogs.com/piyangtao/p/11455920.html
Copyright © 2020-2023  润新知