mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 18:17:20 +00:00
Improve $tw.each() and $tw.modules.applyMethods()
This commit is contained in:
parent
d0ebb159df
commit
7c712c4e03
29
core/boot.js
29
core/boot.js
@ -120,23 +120,30 @@ $tw.utils.hop = function(object,property) {
|
||||
};
|
||||
|
||||
/*
|
||||
Iterate through all the own properties of an object. Callback is invoked with (element,title,object)
|
||||
Determine if a value is an array
|
||||
*/
|
||||
$tw.utils.isArray = function(value) {
|
||||
return Object.prototype.toString.call(value) == "[object Array]";
|
||||
};
|
||||
|
||||
/*
|
||||
Iterate through all the own properties of an object or array. Callback is invoked with (element,title,object)
|
||||
*/
|
||||
$tw.utils.each = function(object,callback) {
|
||||
var f;
|
||||
if(object) {
|
||||
for(var f in object) {
|
||||
if($tw.utils.isArray(object)) {
|
||||
for(f=0; f<object.length; f++) {
|
||||
callback(object[f],f,object);
|
||||
}
|
||||
} else {
|
||||
for(f in object) {
|
||||
if($tw.utils.hop(object,f)) {
|
||||
callback(object[f],f,object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Determine if a value is an array
|
||||
*/
|
||||
$tw.utils.isArray = function(value) {
|
||||
return Object.prototype.toString.call(value) == "[object Array]";
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@ -426,11 +433,15 @@ $tw.modules.getModulesByTypeAsHashmap = function(moduleType,nameField) {
|
||||
Apply the exports of the modules of a particular type to a target object
|
||||
*/
|
||||
$tw.modules.applyMethods = function(moduleType,targetObject) {
|
||||
if(!targetObject) {
|
||||
targetObject = {};
|
||||
}
|
||||
$tw.modules.forEachModuleOfType(moduleType,function(title,module) {
|
||||
$tw.utils.each(module,function(element,title,object) {
|
||||
targetObject[title] = module[title];
|
||||
});
|
||||
});
|
||||
return targetObject;
|
||||
};
|
||||
|
||||
/////////////////////////// Barebones tiddler object
|
||||
|
Loading…
Reference in New Issue
Block a user