mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Improve $tw.each() and $tw.modules.applyMethods()
This commit is contained in:
parent
d0ebb159df
commit
7c712c4e03
37
core/boot.js
37
core/boot.js
@ -119,19 +119,6 @@ $tw.utils.hop = function(object,property) {
|
||||
return Object.prototype.hasOwnProperty.call(object,property);
|
||||
};
|
||||
|
||||
/*
|
||||
Iterate through all the own properties of an object. Callback is invoked with (element,title,object)
|
||||
*/
|
||||
$tw.utils.each = function(object,callback) {
|
||||
if(object) {
|
||||
for(var f in object) {
|
||||
if($tw.utils.hop(object,f)) {
|
||||
callback(object[f],f,object);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Determine if a value is an array
|
||||
*/
|
||||
@ -139,6 +126,26 @@ $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) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Convert "&" to &, "<" to <, ">" to > and """ to "
|
||||
*/
|
||||
@ -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