JavaScript的对象创建
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> //User对象的构造方法 function User(uname,upwd){ this.username=uname; this.pwd=upwd; this.login=function(){ if("admin"===this.username && "111111"===this.pwd){ alert("登陆成功"); }else{ alert("登陆失败"); } } } var user=new User("admin","111111"); user.login(); </script> </head> <body> </body> </html>
和java差不多