本篇文章给大家带来的内容是关于创建对象的三种方式,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
创建对象的三种方式:
1、单体模式
var xxx = {xxx:xxx,xxx:xxx}
(推荐教程:js教程)
2、原型模式
属性放在构造函数里
function teacher(name,age){    this.name = name;    this.age = age;}teacher.prototype.showname = function(){    return this.name;}var xxx = new  teacher('xxx',23);xxx.showname();
3、伪类模式class
class teacher{    constructor(name,age){        this.name = name;        this.age = age;    }    showname(){        return this.name;    }}var xxx = new  teacher('xxx',23);xxx.showname();
更多编程相关内容,请关注编程入门栏目!
以上就是创建对象的三种方式的详细内容。
   
 
   