美文网首页
形参默认值

形参默认值

作者: 牛耀 | 来源:发表于2018-09-25 22:58 被阅读0次
    * 形参的默认值----当不传入参数的时候默认使用形参里的默认值
    function Point(x = 1,y = 2) {
        this.x = x;
        this.y = y;
    }
    
    //定义一个点的坐标的构造函数
        function Point(x = 0, y = 0){
            this.x = x;
            this.y = y;
        }
        let point = new Point(23, 35);
        console.log(point);
        let point1 = new Point();
        console.log(point1);
    

    相关文章

      网友评论

          本文标题:形参默认值

          本文链接:https://www.haomeiwen.com/subject/jnyroftx.html