//手机构造函数 function Phone(brand, price) { this.brand = brand; this.price = price; } //添加 方法 Phone.prototype.call = function() { console.log('我打电话') } //实例化对象 let HuaWei = new Phone('华为', 5888); HuaWei.call(); console.log(HuaWei); //class class Phone1 { //构造方法 名字不能改变 constructor(brand, price) { this.brand = brand; this.price = price; } //方法必须使用该语法 call() { console.log("我打电话"); } } let oneP = new Phone1('xiaomi', 1222); console.log(oneP);
标签:ES6,console,log,price,class,Phone,brand From: https://www.cnblogs.com/xiaobaizitaibai/p/16825325.html