<html> <head> <TITLE>class_obj_js_class</TITLE> <script language=javaScript> var userObj = function(){ }; userObj.prototype={ age:0, name:"huangbiao", getUserName:function(){ return this.name; }, getUserAge:function(){ return this.age; } } function getUserName(){ alert(userObj.prototype.getUserName()); } function getUserAge(){ alert(userObj.prototype.getUserAge()); } function newObj(){ //如果new了一个对象就可以直接访问prototype对象 var newObj = new userObj(); var userName = newObj.getUserName(); alert(userName); var userAge = newObj.getUserAge(); alert(userAge); } </script> <body > <input type="button" value="getName" onclick="getUserName();"></input> <br> <input type="button" value="getUserAge" onclick="getUserAge();"></input> <br> <input type="button" value="getUserAge" onclick="newObj();"></input> </body> </html>
?