实例
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <script type="text/javascript" charset="utf-8"> // 构造函数创建对象 var Obj = function(){ this.name = 'lili'; this.age = 18; this.func = function(){ return document.write('my name is' + this.name + 'my age is' + this.age ); }; }; var obj1 = new Obj(); obj1.func(); // prototype函数添加对象成员 Obj.prototype.sex = 'boy'; document.write('</br>') document.write(obj1.sex); </script> <body> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例