YUI 学习笔记: YAHOO 全局对象 YUI study notes: YAHOO Global Object
10月9th, 2008 — Dreamer October 9th, 2008 - Dreamer今天开始写YUI的学习笔记。 Today was the beginning of YUI the study notes. 其实作为一个初学者,我知道学习JavaScript 还是要从基础学起,最好不要去学习**类库的使用方法,我也一直都在看相应的有关JavaScript基础的资料,大部分的学习还是在那个上面。 In fact, as a beginner, I know that the study JavaScript or from school-based, best not to learn how to use the library **, I have been concerned to see the JavaScript-based information, most of the study or Above that. 不过,既然答应了Blog的事情也不能不做,虽然这个系列可能更新得很慢,还是要写下去:) 今天先开个头,介绍下YUI中最基础的一个东西,英文好的请直接看YUI 官方站点,这里可以无视,没什么新的东西。 However, since the promise of things Blog can not do that while the series may be slow to update, or go on to write:) today opened the first head to introduce the next YUI in a most basic thing, good English please see YUI Official site, you can ignore, not new.
在YUI中,YAHOO 这个字符串是最常见的了,在所有的组件中都会看到。 YUI in China, YAHOO string this is the most common of all the components will see. 因为在YUI中YAHOO是一个全局对象,它为所有YUI类库中的代码提供了一个命名空间(namespace),所以在所有使用了YUI的页面中必须包含YAHOO对象。 YUI because of YAHOO is a global target, which all YUI Library code in a namespace (namespace), so all in the use of the YUI page must include the YAHOO object.
在页面中包含YAHOO全局对象: YAHOO on the page that contains the whole object:
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js” ></script> <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo/yahoo-min.js"> </ script>
注意 ,如果页面中使用了YUI其他的一些组件,那么上面这行代码必须在所有引用YUI组件的script标签前面。 Note that if you use a page of some of the other YUI components, then the above lines of code which must be used in all components of the YUI front of the script tag.
YAHOO全局对象除了为所有的YUI组件提供命名空间之外,还有包含了一些很常用的方法: YAHOO In addition to the overall target for all of the YUI components to provide namespace, but also contains a number of very commonly used method:
- YAHOO.namespace
- YAHOO.lang
- YAHOO.lang.hasOwnProperty
- YAHOO.lang.extend
- YAHOO.lang.augment
- YAHOO.log
- YAHOO_config 和YAHOO.env YAHOO_config and YAHOO.env
- YUI 模块名 YUI module name
1. YAHOO.namespace 1. YAHOO.namespace
这个方法可以用来自定义命名空间。 This method can be used to customize the name space. YUI中YAHOO全局对象会自动创建三个命名空间:YAHOO.util, YAHOO.widget 以及YAHOO.example 。 YUI in the overall YAHOO object will automatically create three namespace: YAHOO.util, YAHOO.widget and YAHOO.example. 如果你想要在YUI的基础上自己写一个组件,或者想把某个产品的所有JS代码放到一个命名空间下来避免和其他JS冲突的话,就可以使用这个方法。 If you want to YUI on the basis of their own to write a component of a product or want all the JS code named on a space down to avoid conflict and other JS, you can use this method. 然后你就可以在自定义的命名空间中定义自己的属性或者方法了。 Then you can customize the namespace defined in their own property or a method.
具体请看这里 Please look at specific here
2.YAHOO.lang 2.YAHOO.lang
这个其实是个对象,它有很多有用的方法,比如isArray(), isFunction() 等,来判断指定的参数是否是数组、函数等。 In fact, this is a target, it has many useful ways, such as isArray (), isFunction (), etc., to determine whether the specified parameters is an array, function, and so on. 还包含了下面要介绍的几个方法。 It also contains the following introduction to a number of ways.
具体请看这里 Please look at specific here
3.YAHOO.lang.hasOwnProperty 3.YAHOO.lang.hasOwnProperty
这个方法可以用来过滤直接添加到Object的原型上的属性。 This method can be used to filter directly added to the prototype of the Object on the property. 其实所有的A级浏览器都已经有hasOwnProperty这种原生方法了,除了Safari 。 In fact, all the A-class browser hasOwnProperty there have been such a primary method, in addition to Safari. 所以为了保险起见还是使用YAHOO.lang.hasOwnProperty比较好。 In order to provide insurance or the sake of used YAHOO.lang.hasOwnProperty better. 而且如果浏览器有hasOwnProperty这种原生方法的话,YAHOO.lang.hasOwnProperty 会进行直接调用。 If you have a browser and hasOwnProperty this primary method, then, YAHOO.lang.hasOwnProperty will direct calls.
具体请看这里 Please look at specific here
4.YAHOO.lang.extend 4.YAHOO.lang.extend
因为JavaScript一开始并没有被设计成面向对象的语言,所以要实现继承就需要一些技巧,而YAHOO.lang.extend就是来帮助你在JavaScript中实现继承的,它消除了很多现有方法的弊端。 JavaScript as the beginning was not designed object-oriented language, so the successor will need to achieve some of the skills, and YAHOO.lang.extend is to help you achieve the succession of JavaScript, and it eliminates many of the drawbacks of existing methods . YAHOO.extend 是YAHOO.lang.extend 的别名,你也可以使用这种缩写。 YAHOO.extend is YAHOO.lang.extend alias, you can also use abbreviations.
具体请看这里 Please look at specific here
5.YAHOO.lang.augment 5.YAHOO.lang.augment
YAHOO.lang.augment 是用来重用现有代码的,用法如下,它可以帮你把对象1原型上的某些或所有属性应用到对象2的原型上。 YAHOO.lang.augment is used to reuse the existing code, use the following, it can help you put an object on a prototype of some or all of the attributes applied to the target 2 on the prototype.
YAHOO.lang.augment(对象2,对象1) YAHOO.lang.augment (target 2, target 1)
YAHOO.augment 是YAHOO.lang.augment 的别名,你也可以使用这种缩写。 YAHOO.augment is YAHOO.lang.augment alias, you can also use abbreviations.
具体请看这里 Please look at specific here
6.YAHOO.log 6.YAHOO.log
这个方法是用来调试的,你可以用它输出一些调试信息。 This method is used for debugging, you can use it to export some of the debugging information. 不过,需要注意的是,这个方法是要和YAHOO.widget.Logger组件配合来使用的,因为只有YAHOO.widget.Logger 组件可以输出YAHOO.log 记录的信息。 But pay attention to is that this is going to YAHOO.widget.Logger components used to meet, because only YAHOO.widget.Logger components can be exported YAHOO.log record. 如果YAHOO.widget.Logger 组件可用的话,YAHOO.log 就会调用YAHOO.widget.Logger.log 方法,否则就什么也不做。 If YAHOO.widget.Logger components can be used, then, YAHOO.log will call YAHOO.widget.Logger.log method, or do nothing.
具体请看这里 Please look at specific here
7.YAHOO_config 和YAHOO.env 7.YAHOO_config and YAHOO.env
YAHOO.env 包含了页面中所加载的所有YUI组件的信息,任何组件都可以使用YAHOO.env.getVersion 来访问到这些信息,当动态加载YUI组件的时候这个方法就特别有用,因为可以查看版本检测依赖关系。 YAHOO.env included in the page to load all the YUI components, any components can be used to YAHOO.env.getVersion access to this information, when the dynamic load YUI components of the time on this particularly useful Because they can view the version of the detection of dependence.
YAHOO_config是一个对象,你可以在它上面定义一个回调函数,这样每当页面中加载一个新的YUI组件的时候,这个回调函数就会自动执行,并且会传送给它一个包含了组件信息的对象。 YAHOO_config is an object, you can top it in the definition of a callback function, so that whenever a new page to load the YUI components, the callback function will be self-executing, and will send it to include a group Pieces of information on the subject.
具体请看这里 Please look at specific here
8.YUI 模块名 8.YUI module name
每个YUI组件都有一个对应的模块名,这些模块名在YUI中都是唯一的。 YUI each component has a corresponding module, these modules in China are the only YUI. 这些模块名会在很多地方都用到(尤其是YUILoader ,因为有时候需要使用YUILoader动态加载组件,这个时候就要传给它所需组件的模块名)。 The modules will be of use in many places (especially YUILoader, because sometimes need to use YUILoader dynamic component loading, this time it is necessary to pass the necessary components of the module).
每个组件对应的模块名请看这里 Corresponding to each of the components of the module look here
本文链接: http://www.zhuoqun.net/html/y2008/1109.html 转载请注明出处,谢谢。 This article link: http://www.zhuoqun.net/html/y2008/1109.html reprint requests reference, thank you.
TrackBack引用地址: http://www.zhuoqun.net/html/y2008/1109.html/trackback TrackBack quoted address: http://www.zhuoqun.net/html/y2008/1109.html/trackback









[...] Dreamer’s Blog » YUI 学习笔记: YAHOO 全局对象(tags: yui) [...] [...] Dreamer's Blog »YUI study notes: YAHOO Global Object (tags: yui) [...]