首页 »Javascript教程 » javascript面向对象:javascript 基础整理总结(面向对象) »正文javascript面向对象:javascript 基础整理总结(面向对象)来源: 发布时间:星期六, 2009年2月14日 浏览:0次 评论:0
="t18">javascript 学习
javascript 大体上可分为3个区别部分组成: 核心(ECMAscript),文本对象(DOM),浏览器对象(BOM) 核心(ECMAscript): 关键字 ![]() ![]() ![]() 文本对象(DOM):DOM将把整个页面规划成由节点层级构成 ![]() 解析遵循 W3C html dom 标准: W3C dom 参考特别关注 DOM Node 介绍说明 BOM 浏览器对象. cookie,弹出新浏览器 ![]() 核心(ECMAscript)Global 内置对象; 思路方法: parseInt ![]() ![]() ![]() 特别注意 eval ![]() ![]() 文本对象(DOM)介绍说明: <bookstore> <book category="cooking"> <title lang="en">Everyday Italian</title> <author>Giada De Laurentiis</author> <year>2005</year> <price>30.00</price> </book> </bookstore> 1. ECMAscript基础 $ 变量弱类型 ; 匈牙利类型标示 : var iOuouValue=100; $ 结束行分号有无都可以; 但再 _disibledevent=> $ 关键字 ; 提别注意 "typeof" var test=1; alert(typeof testX); //output "un ![]() "NaN" - not a number -> isNan("blue"); //output "true" ->isNan("123"); //output "false" $ 对象; var o = ![]() ![]() 这里特别介绍说明下 我们普通写 ![]() ![]() ![]() 这 var a = {name:"刘凯毅"} 等同和 var a = function ![]() 来个 {name:"test",pass:"123456",addr:"bj"} //这是什么 ?! json 当 var str = '{name:"test",pass:"123456",addr:"bj"}' var objectBean = eval(str); //这里就是 对象 objectBea.name 使用了 域概念: <SCRIPT type=text/javascript> var sMessage = 'Hello'; function ![]() ![]() sColor = 'red'; sMessage = 'Hello World!'; } ![]() ![]() alert(sMessage); //Hello World! alert(sColor); //red </SCRIPT> <SCRIPT type=text/javascript> var sMessage = 'Hello'; function ![]() ![]() var sColor = 'red'; sMessage = 'Hello World!'; } ![]() ![]() alert(sMessage); //Hello World! alert(sColor); // 什么都没有 </SCRIPT> <SCRIPT type=text/javascript> var sMessage = 'Hello'; function ![]() ![]() var sColor = 'red'; var sMessage = 'Hello World!'; } ![]() ![]() alert(sMessage); //Hello alert(sColor); // 什么都没有 </SCRIPT> 为面向对象做基础:object prototype 类型 ![]() ![]() // 最简单 ![]() Object.prototype.inObj = 1; function A ![]() { this.inA = 2; } A.prototype.inAProto = 3; B.prototype = ![]() ![]() B.prototype.constructor = B; function B ![]() { this.inB = 4; } B.prototype.inBProto = 5; x = ![]() document.write(x.inObj + ', ' + x.inA + ', ' + x.inAProto + ', ' + x.inB + ', ' + x.inBProto); //1, 2, 3, 4, 5 //增加点信心 http://www.json.org/json.js Object.prototype.toJSONString = function (filter) { ![]() ![]() ![]() ![]() $ arguments ; function getFun ![]() getFun("xx") //output 1 getFun("xx",23) //output 2 $ 语句 ;特殊介绍说明下 for for(var i=0i<iCount;i ![]() 如果无聊 你可以 for( sProp in window ){alert(sProp+"你丫点啊!");} //看看 javascript ![]() 面向对象: var bean = ![]() ![]() 1.工厂思路方法 function getAttr ![]() alert(this.attr) } function Bean(tattr){ var bean = ![]() bean.attr = tattr; bean.getAttr = getAttr; ![]() } 根本就是山寨版 面向对象 2.构造 function Bean(tattr){ this.attr = tattr ; bean.getAttr = function ![]() alert(this.attr); } } 其上 2 总 再Bean 对象创建时 ![]() ![]() 3.原型模式 function Bean ![]() Bean.prototype.attr = ""; Bean.prototype.getAttr=function ![]() 解决 “重复生成 ![]() ![]() ![]() ![]() ![]() 其 ![]() ![]() ![]() 4.混合 模型 :) 哈哈 function Bean ![]() this.attr= ""; this.getArray= ![]() } Bean.prototype.getAttr=function ![]() 5.动态原型 (注意下面开始 ![]() ![]() function Bean ![]() this.attr= ""; this.getArray= ![]() // ![]() ![]() ![]() ![]() Bean.prototype.getAttr=function ![]() Bean._initialized= true ; } } /****************************************************************/ 对象继承 1.对象冒充!!(可支持多继承 ![]() function ![]() this.color = sstr ; this.sayColor = function ![]() alert(this.color); }; } function ![]() ![]() function ![]() ![]() this. ![]() this. ![]() ![]() delete this. ![]() this. ![]() this. ![]() ![]() delete this. ![]() this.arrt = "google"; } 2.call ![]() ![]() function ![]() this.color = sstr ; this.sayColor = function(str){ alert(str+this.color); }; } function ![]() ![]() // this. ![]() // this. ![]() ![]() // delete this. ![]() ![]() // ![]() ![]() this.arrt = "baidu"; } 3.正统 ![]() function ![]() ![]() ![]() function ![]() ![]() ![]() ![]() ![]() ![]() ![]() alert( this.color ); } var bb = ![]() ![]() bb.sayName ![]() alert(bb.oo); // output test alert( bb instanceof ![]() alert( bb instanceof ![]() 4.如果你要多继承!!并且还支持 instanceof 混合方式: function ![]() ![]() function ![]() ![]() function ![]() ![]() ![]() ![]() } ![]() ![]() ![]() 0
相关文章
读者评论发表评论 |
|