base.js revision 9bd4bbae8fe38ed2b644bec08d4119e97434f96f
fc67d6c0ec40e25fd6756153861ebdb65e577014Dav Glass * The base module provides the Base class, which objects requiring attribute and custom event support can extend.
748017e442bd0838f8ff8cf53f67e6aaf31484e1Dav Glass * The module also provides two ways to reuse code - An augmentable Plugin.Host interface which provides plugin support
fc67d6c0ec40e25fd6756153861ebdb65e577014Dav Glass * (which is augmented to the Base class) and Base.build which provides a way to
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * build custom classes using extensions.
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * @module base
584a3165a723f446237d89a45d03424c03606ed5Dav Glass * The base-base submodule provides the Base class and augmentable Plugin.Host implementation,
584a3165a723f446237d89a45d03424c03606ed5Dav Glass * without the extension support provided by Base.build.
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * @module base
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * @submodule base-base
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass var O = Y.Object,
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass OBJECT_CONSTRUCTOR = Object.prototype.constructor,
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * A base class which objects requiring attributes and custom event support can
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * extend. Base also handles the chaining of initializer and destructor methods across
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * the hierarchy as part of object construction and destruction. Additionally, attributes configured
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * through the static <a href="#property_Base.ATTRS">ATTRS</a> property for each class
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * in the hierarchy will be initialized by Base.
748017e442bd0838f8ff8cf53f67e6aaf31484e1Dav Glass * The static <a href="#property_Base.NAME">NAME</a> property of each class extending
748017e442bd0838f8ff8cf53f67e6aaf31484e1Dav Glass * from Base will be used as the identifier for the class, and is used by Base to prefix
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * all events fired by instances of that class.
3be83a94a2eca59b109251c4b7c99b99af927f82Dav Glass * @class Base
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @constructor
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @uses Attribute
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @uses Plugin.Host
fec0b12eb7538bebc558c3efe1c7f31e295cdc82Dav Glass * @param {Object} config Object with configuration property name/value pairs
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass function Base() {
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass if (this._lazyAddAttrs !== false) { this._lazyAddAttrs = true; }
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * The list of properties which can be configured for
100b8bd9adaf6900bd0dfb6083a8a788ca8cf23cDav Glass * each attribute (e.g. setter, getter, writeOnce, readOnly etc.)
c94489fa397a00c551bc087b783123fde4efb904Dav Glass * @property Base._ATTR_CFG
c94489fa397a00c551bc087b783123fde4efb904Dav Glass * @type Array
* Attribute's <a href="Attribute.html#method_addAttr">addAttr</a> method, the attribute
initialized: {
readOnly:true,
value:false
destroyed: {
readOnly:true,
value:false
queuable:false,
if (config) {
destroy: function() {
queuable:false,
_defInitFn : function(e) {
if (this._initPlugins) {
_defDestroyFn : function(e) {
this._destroyHierarchy();
if (this._destroyPlugins) {
this._destroyPlugins();
* @return {Function[]} An array of classes (constructor functions), making up the class hierarchy for this object.
* This value is cached the first time the method, or _getAttrCfgs, is invoked. Subsequent invocations return the
_getClasses : function() {
if (!this._classes) {
this._initHierarchyData();
return this._classes;
* This value is cached the first time the method, or _getClasses, is invoked. Subsequent invocations return
_getAttrCfgs : function() {
if (!this._attrs) {
this._initHierarchyData();
return this._attrs;
* of an object with attribute name/configuration pairs.
if (attrs) {
return cfgs;
_initHierarchyData : function() {
var c = this.constructor,
classes = [],
attrs = [];
if (c.ATTRS) {
var attr,
cfg,
val,
path,
aggAttrs = {};
if (allAttrs) {
if (val) {
if ( (clone === undefined && (OBJECT_CONSTRUCTOR === val.constructor || L.isArray(val))) || clone === DEEP || clone === true) {
path = null;
} else if (!path){
return aggAttrs;
ci,
ei,
el,
_destroyHierarchy : function() {
var constr,
toString: function() {
* Alias for <a href="Plugin.Host.html#method_Plugin.Host.plug">Plugin.Host.plug</a>. See aliased
* Alias for <a href="Plugin.Host.html#method_Plugin.Host.unplug">Plugin.Host.unplug</a>. See the
L = Y.Lang;
* @param {Function} name The name of the new class. Used to defined the NAME property for the new class.
* augmented/aggregated to the built class.
if (dynamic) {
if (aggregates) {
if (aggregates) {
if (dynamic) {
return builtClass;
function BuiltClass() {
l = f.length,
return BuiltClass;
id: null,
exts : [],
return builtClass;
var aggr = [],
c = main,
while (c && c.prototype) {
if (classAggr) {
if (cfgAggr) {
return aggr;