//(1)對象字面量的方式 person={firstname:"Mark",lastname:"Yun",age:25,eyecolor:"black"};(2)用function來模擬無參的構造函數function Person(){}var person = new Person(); //定義一個function,如果使用new"實例化",該function可以看作是一個Classperson.name = "Xiaosong";person.age = "23";person.work = function() {alert("Hello " + person.name);}person.work();(3)用function來模擬參構造函數來實現(用this關鍵字定義構造的上下文屬性)function Person(name,age,hobby) { this.name = name; //this作用域:當前對象this.age = age;this.work = work;this.info = function() {alert("我叫" + this.name + ",今年" + this.age + "歲,是個" + this.work);}}var Xiaosong = new Person("WooKong",23,"程序猿"); //實例化、創建對象Xiaosong.info(); //調用info()方法(4)用工廠方式來創建(內置對象)var jsCreater = new Object();jsCreater.name = "Brendan Eich"; //JavaScript的發明者 jsCreater.work = "JavaScript";jsCreater.info = function() {alert("我是"+this.work+"的發明者"+this.name);}jsCreater.info();(5)用原型方式來創建function Standard(){}Standard.prototype.name = "ECMAScript";Standard.prototype.event = function() {alert(this.name+"是腳本語言標準規範");}var jiaoben = new Standard();jiaoben.event();(6)用混合方式來創建 function iPhone(name,event) {this.name = name;this.event = event;}iPhone.prototype.sell = function() {alert("我是"+this.name+",我是iPhone5s的"+this.event+"~ haha!");}var SE = new iPhone("iPhone SE","官方翻新機");SE.sell();eval 是做什麼的?它的功能是把對應的字符串解析成JS代碼並運行;應該避免使用eval,因為不安全,非常耗性能(2次,一次解析成js 語句,一次執行)。null 和 undefined 有何區別?null 表示一個對象被定義了,值為“空值”;undefined 表示不存在這個值。typeof undefined //"undefined"undefined :是一個表示"無"的原始值或者說表示"缺少值",就是此處應該有一個值,但是還沒有定義。當嘗試讀取時會返回 undefined;例如變量被聲明瞭,但沒有賦值時,就等於undefined。typeof null //"object"null : 是一個對象(空對象, 沒有任何屬性和方法);例如作為函數的參數,表示該函數的參數不是對象;注意: 在驗證null時,一定要使用 === ,因為 == 無法分別 null 和 undefined 分享到: 閱讀更多 普託邦大博士 的文章 關鍵字: 知識 編程語言 JavaScript