今天在看完xtree.js代碼后,發(fā)現(xiàn)一個問題。在執(zhí)行javascript的document.write(obj)方法時,如果obj實現(xiàn)了prototype的toString()方法,document.wirte方法將能自動調(diào)用obj的toString()方法。代碼如下:
???/*----------?? 樹構(gòu)造代碼 ---------*/
??????? if (document.getElementById) {
?????????? var tree = new WebFXTree('Root');
?????????? tree.setBehavior('classic');
?????????? var a = new WebFXTreeItem('1');
?????????? tree.add(a);
?????????? var b = new WebFXTreeItem('1.1');
?????????? a.add(b);
????????? b.add(new WebFXTreeItem('1.1.1'));
????????? b.add(new WebFXTreeItem('1.1.2'));
????????? b.add(new WebFXTreeItem('1.1.3'));
????????? var f = new WebFXTreeItem('1.1.4');
????????? b.add(f);
???????? document.write(tree);
/*------------------ xtree.js代碼片段 ----------*/
WebFXTree.prototype.toString = function() {
alert("it's here!");
?var str = "<div id=\"" + this.id + "\" ondblclick=\"webFXTreeHandler.toggle(this);\" class=\"webfx-tree-item\" onkeydown=\"return webFXTreeHandler.keydown(this, event)\">" +
??"<img id=\"" + this.id + "-icon\" class=\"webfx-tree-icon\" src=\"" + ((webFXTreeHandler.behavior == 'classic' && this.open)?this.openIcon:this.icon) + "\" onclick=\"webFXTreeHandler.select(this);\">" +
??"<a href=\"" + this.action + "\" id=\"" + this.id + "-anchor\" onfocus=\"webFXTreeHandler.focus(this);\" onblur=\"webFXTreeHandler.blur(this);\"" +
??(this.target ? " target=\"" + this.target + "\"" : "") +
??">" + this.text + "</a></div>" +
??"<div id=\"" + this.id + "-cont\" class=\"webfx-tree-container\" style=\"display: " + ((this.open)?'block':'none') + ";\">";
?var sb = [];
?for (var i = 0; i < this.childNodes.length; i++) {
??sb[i] = this.childNodes[i].toString(i, this.childNodes.length);
?}
?this.rendered = true;
?return str + sb.join("") + "</div>";
};
經(jīng)過跟蹤,證實在執(zhí)行document.write(tree)時,調(diào)用了WebFXTree.prototype.toString 方法。
| |||||||||
日 | 一 | 二 | 三 | 四 | 五 | 六 | |||
---|---|---|---|---|---|---|---|---|---|
27 | 28 | 1 | 2 | 3 | 4 | 5 | |||
6 | 7 | 8 | 9 | 10 | 11 | 12 | |||
13 | 14 | 15 | 16 | 17 | 18 | 19 | |||
20 | 21 | 22 | 23 | 24 | 25 | 26 | |||
27 | 28 | 29 | 30 | 31 | 1 | 2 | |||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
常用鏈接
留言簿(1)
隨筆分類(17)
- arithmetics(3)
- C/C++(1)
- Cache
- DB(1)
- IOC/AOP(2)
- java concurrency(2)
- java 多線程
- JDK(1)
- JVM(1)
- Linux(1)
- nosql(5)
- Performance
隨筆檔案(28)
- 2014年7月 (3)
- 2014年5月 (1)
- 2014年4月 (1)
- 2013年6月 (1)
- 2013年4月 (2)
- 2013年3月 (1)
- 2012年8月 (1)
- 2012年5月 (1)
- 2012年2月 (6)
- 2012年1月 (1)
- 2011年10月 (1)
- 2011年9月 (1)
- 2011年6月 (2)
- 2009年8月 (3)
- 2008年5月 (1)
- 2006年4月 (2)
文章分類(30)
- AJAX
- common(3)
- DB(3)
- java tools(1)
- JAVA 基礎(chǔ)文章(1)
- java 并發(fā)(3)
- JDBC(1)
- linux(3)
- ORM(包括hibernate等)(2)
- Spring(6)
- SWT、SWING、AWT(2)
- web(2)
- web service
- 優(yōu)化(2)
- 版本控制(1)
文章檔案(30)
- 2013年4月 (1)
- 2013年3月 (1)
- 2012年1月 (2)
- 2011年12月 (1)
- 2011年11月 (1)
- 2011年8月 (2)
- 2011年7月 (1)
- 2011年6月 (4)
- 2011年4月 (3)
- 2009年8月 (4)
- 2008年6月 (1)
- 2008年4月 (1)
- 2007年3月 (2)
- 2006年12月 (1)
- 2006年10月 (2)
- 2006年8月 (1)
- 2006年6月 (1)
- 2006年4月 (1)
相冊
收藏夾(2)
hibernate
java基礎(chǔ)
mysql
xml
- IBM XSL
- w3c標(biāo)準(zhǔn)的xpath說明
- web service ibm
- XPath 示例
- XPath 簡單語法
- XQuery 1.0 and XPath 2.0 Full-Text Use Cases
關(guān)注
壓力測試
算法
最新隨筆
- 1.?解決Redis數(shù)據(jù)庫響應(yīng)延遲問題(轉(zhuǎn)載)
- 2.?理想化的 Redis 集群 (轉(zhuǎn)載)
- 3.?Redis 分區(qū)(翻譯)
- 4.?Mysql索引相關(guān)知識分享
- 5.?數(shù)據(jù)結(jié)構(gòu)-BinaryTree
- 6.?深入學(xué)習(xí)Linux之命令篇-find
- 7.?什么情況下應(yīng)該使用GridFS(翻譯)
- 8.?Mongodb主從復(fù)制實踐
- 9.?jmap使用
- 10.?為什么實現(xiàn)了equal方法,一定需要實現(xiàn)hashCode方法呢?
- 11.?MongoDB學(xué)習(xí)—MongoDB安裝
- 12.?京東碰到的一道面試題
- 13.?HashMap分析
- 14.?12個小球其中有一個是次品,不過不知道輕重,請問用天平能用三次測量的機會找出那個次品嗎?
- 15.?使用java nio 實現(xiàn) Ping
- 16.?Spring 源碼閱讀(IOC容器)-容器啟動2
- 17.?Spring 源碼閱讀(IOC容器)-容器啟動1
- 18.?JDBC SavePoint淺析
- 19.?Linux下C訪問MySQL實踐
- 20.?Apache Benchmark(ab)使用
- 21.?Java NIO Demo
- 22.?Amoeba源碼解讀一
- 23.?編寫跨平臺代碼注意事項
- 24.?編寫跨平臺代碼注意事項
- 25.?JavaScript的toString()方法自動調(diào)用
搜索
積分與排名
- 積分 - 96393
- 排名 - 601
最新評論

- 1.?嗯嗯
- 阿斯達(dá)斯
- --安德森
- 2.?re: tomcat 產(chǎn)生heapdump文件配置
- 如果不內(nèi)存溢出,heapdump目錄是不是空的?
- --小龍在線
- 3.?re: Java NIO Demo
- 評論內(nèi)容較長,點擊標(biāo)題查看
- --zuidaima
- 4.?re: Redis 分區(qū)(翻譯)
- 手機賺錢軟件http://www.szapk.cn!!!
- --手機賺錢軟件http://www.szapk.cn
- 5.?re: Mysql索引相關(guān)知識分享
- 很有價值的分享,值得學(xué)習(xí)
- --任務(wù)大廳
閱讀排行榜
評論排行榜
- 1.?Mysql索引相關(guān)知識分享(4)
- 2.?京東碰到的一道面試題(1)
- 3.?Linux下C訪問MySQL實踐(1)
- 4.?Apache Benchmark(ab)使用(1)
- 5.?Java NIO Demo(1)
- 6.?JavaScript的toString()方法自動調(diào)用(1)
- 7.?lucene 實踐(1)
- 8.?Redis 分區(qū)(翻譯)(1)
- 9.?解決Redis數(shù)據(jù)庫響應(yīng)延遲問題(轉(zhuǎn)載)(0)
- 10.?理想化的 Redis 集群 (轉(zhuǎn)載)(0)
- 11.?dom4j學(xué)習(xí)筆記(0)
- 12.?創(chuàng)建mysql innodb數(shù)據(jù)庫(0)
- 13.?Amoeba源碼解讀一(0)
- 14.?編寫跨平臺代碼注意事項(0)
- 15.?編寫跨平臺代碼注意事項(0)
- 16.?HashMap分析(0)
- 17.?12個小球其中有一個是次品,不過不知道輕重,請問用天平能用三次測量的機會找出那個次品嗎?(0)
- 18.?使用java nio 實現(xiàn) Ping(0)
- 19.?Spring 源碼閱讀(IOC容器)-容器啟動2(0)
- 20.?Spring 源碼閱讀(IOC容器)-容器啟動1(0)