
本篇文章给大家带来的内容是关于创建对象的三种方式,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
创建对象的三种方式:
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();更多编程相关内容,请关注php中文网编程入门栏目!
以上就是创建对象的三种方式的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号