botanjs/src/System/utils/_this.js
raw ยท 815 bytes
(function(){
var ns = __namespace( "System.utils" );
// Get prop from obj if obj.<prop> is <type>
var objGetProp = function ( obj, prop, type )
{
if(obj && obj[prop])
{
var t = obj[prop].constructor.toString().match(/function ([^\(]+)/);
if(t && t.length == 2 && t[1].toUpperCase() == type.toUpperCase())
{
return obj[prop];
}
}
return null;
};
var objSearch = function ( obj, cond, prop )
{
for( var i in obj )
{
if( cond( obj[i] ) )
{
return obj[i][prop] || obj[i];
}
}
return null;
};
var objMap = function( obj, callback )
{
for( var i in obj )
{
obj[i] = callback( obj[i] );
}
};
ns[ NS_EXPORT ]( EX_FUNC, "objGetProp", objGetProp );
ns[ NS_EXPORT ]( EX_FUNC, "objSearch", objSearch );
ns[ NS_EXPORT ]( EX_FUNC, "objMap", objMap );
})();