9. Y.Array
• dudupe • map
• each • numericSort
• every • partition
• filter • reduce
• find • reject
• grep • some
• hashindexOf • test
• Invoke • unique
• lastIndexOf • zip
10. Y.mix
mix ( receiver supplier [overwrite=false] [whitelist] [mode=0] [merge=false] )
Mixes supplier's properties into receiver.
0: Default. Object to object.
1: Prototype to prototype.
2: Prototype to prototype and object to object.
3: Prototype to object.
4: Object to prototype.
Y.mix(AttributeEvents, EventTarget, false, null, 1);
Y.mix(Attribute, Y.AttributeEvents, true, null, 1);
Y.mix(Base, Attribute, false, null, 1);
Y.aggregate = function(r, s, ov, wl) {
return Y.mix(r, s, ov, wl, 0, true);
};
11. Y.extend
Create Class Hierarchies with extend
Y.extend = function(r, s, px, sx) { function Bird(name) {
var sp = s.prototype, rp = Y.Object(sp); this.name = name;
r.prototype = rp; }
rp.constructor = r;
r.superclass = sp; Bird.prototype.flighted = true; //
// add prototype overrides Default for all Birds
if (px) {
Y.mix(rp, px, true);
} function Chicken(name) {
// add object overrides Chicken.superclass.constructor.call
if (sx) { (this, name);
Y.mix(r, sx, true); }
} Y.extend(Chicken, Bird);
return r; Chicken.prototype.flighted = false;
};
12. Y.augment
augment ( receiver supplier [overwrite=false] [whitelist] [args] )
Augments the receiver with prototype properties from the supplier.
The receiver may be a constructor function or an object. The
supplier must be a constructor function.
Y.augment(TreeNode, Y.EventTarg function Foo() {}
et, true, null, { Foo.prototype.doSomething = function () {};
emitFacade: true, function Bar() {}
prefix: 'tree' Y.augment(Bar, Foo);
}); varb = new Bar();
if (binstanceof Bar) {} // true
if (binstanceofFoo) {} //false
13. Y.Object
Prototype inheritance
Y.Object = Lang._isNative(Object.create) ? function (obj) {
return Object.create(obj);
} : (function () {
function F() {}
return function (obj) {
F.prototype= obj;
return new F();
};
}());
14. Y.merge
Returns a new object containing all of the properties of all the supplied objects. The
properties from later objects will overwrite those in earlier objects.
var set1 = { foo : "foo" };
var set2 = { foo : "BAR", bar : "bar" };
var set3 = { foo : "FOO", baz : "BAZ" };
var merged = Y.merge(set1, set2, set3);
//{foo => FOO, bar => bar, baz => BAZ}
15. Y.clone
clone ( o safe fc owner cloned )
Deep object/array copy.
yeach(o, function(v, k) {
if (k == 'prototype') {
// skip the prototype
// } else if (o[k] === o) {
// this[k] = this;
} else {
this[k] =
Y.clone(v, safe, f, c, owner || o, marked);
}
}, o2);
16. Module
YUI.add("mywidget", function(Y) {
function MyWidget(){}
Y.namespace(‘MyWidget’) = MyWidget;
}, "1.0.0", {requires:["widget", "substitute"]});
YUI.use(‘mywidget’, function(Y){
new Y.MyWidget();
});
A module's add() callback isn't executed until that module is attached to a
YUI instance via use(). Each time a module is attached via use(), the module's
add() callback will be executed, and will receive as an argument the same YUI
instance that will later be passed to the use() callback.
17. Loader
• Built into YUI Global Object
• Self-aware dependency management
• Asynchronous combo-loaded from CDN
• Sandboxed Code
• Dynamic Loading withuse() method
YUI().use('calendar', function (Y) {
Y.use('autocomplete', function () {
// The autocomplete module is available here, and the calendar module
});
});
18. Event
• Dom Events
• Custom Events
• Event API
• Custom Events more DOM like
• “After” subscriptions
• Unified subscription