构造函数,通过原型添加方法,以下语法,手动修改构造器的指向
实例化对象,并初始化,调用方法
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>title</title> <script> function student(name, age, sex) { this.name = name; this.age = age; this.sex = sex; } //简单的原型写法 student.prototype = { //手动修改构造器的指向 constructor: student, height: "188", weight: "70kgs", study: function () { console.log("学习12小时"); }, eat: function () { console.log("吃午饭"); } }; //实例化对象,并初始化 var stu = new student("段飞", 20, "男");
//调用方法 stu.eat(); stu.study(); console.dir(stu); console.dir(student); </script> </head> <body> </body> </html>
如对本文有疑问, 点击进行留言回复!!
asp.net中ajax和一般处理程序(handler.ashx)的交互
egg.js创建项目,目录介绍,简单使用,sequelize mysql使用
网友评论