mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-25 09:30:28 +00:00
Merge pull request #1145 from tobibeer/allow-to-break-each
allows to break out of $tw.utils.each
This commit is contained in:
commit
136c00237e
17
boot/boot.js
17
boot/boot.js
@ -62,14 +62,23 @@ $tw.utils.isDate = function(value) {
|
||||
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;
|
||||
var next,f;
|
||||
|
||||
if(object) {
|
||||
if(Object.prototype.toString.call(object) == "[object Array]") {
|
||||
object.forEach(callback);
|
||||
for (f=0; f<object.length; f++) {
|
||||
next = callback(object[f],f,object);
|
||||
if(next === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(f in object) {
|
||||
if(Object.prototype.hasOwnProperty.call(object,f)) {
|
||||
callback(object[f],f,object);
|
||||
next = callback(object[f],f,object);
|
||||
if(next === false) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1958,4 +1967,4 @@ if(typeof(exports) !== "undefined") {
|
||||
exports.TiddlyWiki = _boot;
|
||||
} else {
|
||||
_boot(window.$tw);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user