多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**JS类实现代码** ~~~ var student = { name:"名字", age:"年龄", sex:"性别", number:"学号" } function student(name,age) { this.name = name; this.age = age; } student.prototype.sex="男"; student.prototype.number = function(){ console.log("20170101"); } var stu1 = new student("小马",21); var stu2 = new student("小明",30); console.log(stu1.sex); stu2.number(); console.log(stu1.name); ~~~ **错误实例** ~~~ function student(name,age) { this.nameS = name; this.age = age; this.number = function(){ return getName(); } function getName(){ return this.nameS; } function getAge(){ return this.age; } } student.prototype.sex="男"; student.prototype.number = function(){ console.log("20170101"); } var stu1 = new student("小马",21); var stu2 = new student("小明",30); console.log(stu1.number()); ~~~