日期:2014-05-16 浏览次数:20350 次
<HTML> <HEAD> <script type="text/javascript"> function Person(firstName, lastName, age){ // 私有变量 var _firstName = firstName; var _lastName = lastName; // 公用变量 this.age = age; // 方法 this.getname = function(){ return (firstName+ "" + lastName); }; this.sayHello = function(){ alert( "Hello, I am" + firstName + " " + lastName); }; }; var BillGates = new Person("Bill", "Gates" , 54); var SteveNash = new Person("Steve" , "Nash" , 53); BillGates.sayHello(); SteveNash.sayHello(); alert(BillGates.getname() + "" + BillGates.age); alert(BillGates._firstName); // you can't access to this variable </script> <TITLE> New Document </TITLE> </HEAD> <BODY> </BODY> </HTML>