您的位置 首页 > 腾讯云社区

为class添加方法,对象合并---用户4344670

// class Point { toString() { console.log("打印"); } } // 为类添加方法:方式一 Point.prototype.say = function() { console.log(" 360"); }; // 为类添加方法:方式二 Object.assign 是对象合并的意思 Object.assign(Point.prototype, { getName: function() { console.log(" 852852"); }, getAge: function() { console.log(" 85285289"); } }); // this.say Object.assign ( { name: '1',age: 2}, { si: 'status',age: 5220 }) class People { say() { console.log( " say"); } }; let obj = new Point(); obj.toString(); obj.say(); obj.getName(); ---来自腾讯云社区的---用户4344670

关于作者: 瞎采新闻

这里可以显示个人介绍!这里可以显示个人介绍!

热门文章

留言与评论(共有 0 条评论)
   
验证码: