JavaScript闭包
<!DOCTYPE HTML> <HTML> <HEAD> <TITLE> New Document </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- //结构比较清晰的闭包 window.ChatLog1 = function(){ function _ChatJS(){ this.test = function(){ alert(1); } this.aa = "aa"; this.test2 = function(){ alert(aa); } //将aa定义成常量,youyu4 Object.defineProperty(this, "aa", { writable: false, //不可修改 configurable: false //不可被删除 //value: "aa1" }); } return new _ChatJS(); }(); //传统的闭包形式 var person = { name: "Nicholas", age: 29, job: "Software Engineer", sayName: function(){ alert(this.name); } }; ChatLog1.aa = "bb"; alert(ChatLog1.aa); //--> </SCRIPT> </HEAD> <BODY> </BODY> </HTML>
New Document
相关推荐
yuwinter 2020-10-14
nmgxzm00 2020-11-10
ifconfig 2020-10-14
hhanbj 2020-11-17
zfszhangyuan 2020-11-16
古叶峰 2020-11-16
一个智障 2020-11-15
jipengx 2020-11-12
81427005 2020-11-11
xixixi 2020-11-11
游走的豚鼠君 2020-11-10
苗疆三刀的随手记 2020-11-10
Web卓不凡 2020-11-03
小飞侠V 2020-11-02
帕尼尼 2020-10-30
爱读书的旅行者 2020-10-26
帕尼尼 2020-10-23
杏仁技术站 2020-10-23