From 047cf5813dc0e10815cbdfa36db5959ba308d648 Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 21 May 2012 22:05:49 +0200 Subject: [PATCH] use 'this', not 'window', as global object; allow for Ox.break in Ox.loop --- source/Ox/js/Core.js | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/source/Ox/js/Core.js b/source/Ox/js/Core.js index 7bcc60e2..36446411 100644 --- a/source/Ox/js/Core.js +++ b/source/Ox/js/Core.js @@ -22,7 +22,7 @@ Some conventions: k key (of a key/value pair) key key (of a key/value pair) max maximum value - min minumum value + min minimum value num number obj object re regexp @@ -71,15 +71,17 @@ Some conventions: // todo: check http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ // also see https://github.com/tlrobinson/narwhal/blob/master/lib/util.js -/*@ -Ox The Ox object - See Ox.wrap for details. - (value) -> wrapped value - value <*> Any value -@*/ -window.Ox = function(val) { - return Ox.wrap(val); -}; +(function(global) { + /*@ + Ox The Ox object + See Ox.wrap for details. + (value) -> wrapped value + value <*> Any value + @*/ + global.Ox = function(val) { + return Ox.wrap(val); + }; +})(this); /*@ Ox.load Loads a module @@ -255,9 +257,16 @@ Ox.loop = function() { step = len == 4 ? arguments[2] : (start <= stop ? 1 : -1), fn = arguments[len - 1], i; - for (i = start; step > 0 ? i < stop : i > stop; i += step) { - if (fn(i) === false) { - break; + try { + for (i = start; step > 0 ? i < stop : i > stop; i += step) { + if (fn(i) === false) { + console.warn('Returning false in Ox.loop is deprecated.') + break; + } + } + } catch(e) { + if (e !== Ox.BreakError) { + throw e; } } return i; @@ -313,7 +322,6 @@ Ox.print Prints its arguments to the console > Ox.print('foo').split(' ').pop() "foo" @*/ - Ox.print = function() { var args = Ox.toArray(arguments), date = new Date(); @@ -332,7 +340,6 @@ Ox.uid Returns a unique id > Ox.uid() != Ox.uid() true @*/ - Ox.uid = (function() { var uid = 0; return function() { @@ -354,7 +361,6 @@ Ox.wrap Wraps a value so that one can directly call any Ox function on it > Ox.wrap("foobar").value() "foobar" @*/ - Ox.wrap = function(val, chained) { // somewhat inspired by underscore.js var wrapper = {