作业1创建一个构造函数
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js构造函数作业</title> </head> <body> <script> var CreateObj = function() { this.dommin = 'php.cn'; this.get = function (value) { var site = 'php中文网'; return site + value; } } var obj1 = new CreateObj(); console.log(obj1.dommin); console.log(obj1.get(obj1.dommin)); var obj2 = new CreateObj(); console.log(obj2.dommin); console.log(obj2.get(obj2.dommin)); </script> </body> </html>
作业2:
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js构造函数作业</title> </head> <body> <script> var CreateObj = function() { this.dommin = 'php.cn'; this.get = function (value) { var site = 'php中文网'; return site + value; } } CreateObj.prototype.email='yangfaguo@qq.com'; CreateObj.prototype.hellow=function () { return 'js不好玩'; }; var obj= new CreateObj(); console.log(obj.email); console.log(obj.hellow); </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
点击 "运行实例" 按钮查看在线实例