08月19, 2013

对象的事,你怎么看?

话说啥是对象? 哈哈, js一切皆是对象

var 测试 = (function () { 
 var 对象 = {};
 对象.打印 = function () {
 return window.console && console.log && Function.prototype.apply.call(console.log,console,Array.prototype.slice.call(arguments,0)),对象;
 }
 对象.容器 = null;
 对象.作者 = "xieliang";
 对象.时间 = "20130817";
 对象.输出代码到页面 = function () { 
 对象.打印("开始输出代码");
 var div = document.createElement("div");
 对象.容器 = div;
 div.zIndex = "9999999";
 div.innerHTML = "哈哈";
 div.style.backgroundColor = "#ccc";
 div.style.textAlign = "center";
 div.style.height = "30px";
 div.style.lineHeight = "30px";
 div.style.width = "100px";
 div.style.position = "fixed";
 div.style.left = "50%";
 div.style.top = "50%";
 div.style.marginLeft = "-50px";
 div.style.marginTop = "-15px";
 div.style.border = "1px solid #09f";
 document.body.appendChild(div);
 对象.打印("输出代码完毕");
 return 对象;
 }
 对象.绑定事件 = function () {
 var self = 对象;
 self.打印("开始绑定事件");
 self.容器.onclick = function () { 
 self.打印("你点击了我, 我的innerHTML 为 : "+ this.innerHTML);
 }
 self.打印("绑定事件结束");
 return self;
 }
 对象.初始化 = function() {
 return 对象.打印("开始初始化").输出代码到页面().绑定事件().打印("初始化结束");
 }
 return 对象.初始化;
})();
测试();

只是谢亮个人看法.

本文链接:https://xuexb.com/post/175.html

-- EOF --

发表于 2013年08月19日 16:19:45 ,添加在分类 前端技术 下 ,最后修改于 2016年07月16日 16:19:45

提醒: 本文最后更新于 3463 天前,文中所描述的信息可能已发生改变,请谨慎使用。

Comments

评论加载中...

注:如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理。

AltStyle によって変換されたページ (->オリジナル) /