0
点赞
收藏
分享

微信扫一扫

JS中的构造函数的使用

AbrahamW 2022-01-31 阅读 66

JavaScript中的构造函数的使用

function Person(name,age){
    this.name = name;
    this.age = age;
    this.showID = function (){
        console.log("My name is " + this.name);
        console.log("I'm " + this.age +" years old");
    }
}

let Ulrich = new Person('Ulrich',22);
Ulrich.showID();

输出结果:
在这里插入图片描述

举报

相关推荐

0 条评论