大众世界 world of demotic + 社区新动力

 找回密码
 注册会员
搜索
查看: 5836|回复: 0

[Javascript] 几行代码搞定YUI3的核心对象

[复制链接]
发表于 2010-12-10 16:26:09 | 显示全部楼层 |阅读模式
  1. function a(){
  2.     this.firstAttr = 'i an the original this.first';
  3.     this.firstMethod = function(){
  4.         //this is the first original firstMethod()
  5.     };
  6. }
  7. a.prototype = {
  8.     constructor:a,
  9.     init:function(){
  10.         this.installAttr= "i am the installed by this.init()";
  11.         this.installMethod= function(){"i am a method installed by this.init()";}
  12.     }
  13. }
  14. var b = new a();//这里的b是一个纯洁的天使。。。
  15. b.init();//初始化安装属性,方法,天使被装上了翅膀。。。
复制代码
最后得到的这个对象b已经很牛X的拥有原生this中的属性和方法 + init() 方法中安装的属性和方法。
console.log(b)
这就是顶顶大名的yui3的原生对象核心机制。
再加上add动态添加,use方法配合loader模块动态挂载使用,成就了YUI为万人敬仰的牛X框架。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Archiver|手机版|小黑屋|Wod Inc. ( 蜀ICP备20000008号-8

GMT+8, 2024-5-10 20:26 , Processed in 0.096400 second(s), 30 queries .

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表