use 'this', not 'window', as global object; allow for Ox.break in Ox.loop

This commit is contained in:
rolux 2012-05-21 22:05:49 +02:00
parent 75558d4b9d
commit 047cf5813d

View file

@ -22,7 +22,7 @@ Some conventions:
k key (of a key/value pair) k key (of a key/value pair)
key key (of a key/value pair) key key (of a key/value pair)
max maximum value max maximum value
min minumum value min minimum value
num number num number
obj object obj object
re regexp re regexp
@ -71,15 +71,17 @@ Some conventions:
// todo: check http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ // 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 // also see https://github.com/tlrobinson/narwhal/blob/master/lib/util.js
/*@ (function(global) {
Ox <f> The <code>Ox</code> object /*@
Ox <f> The <code>Ox</code> object
See <code>Ox.wrap</code> for details. See <code>Ox.wrap</code> for details.
(value) -> <o> wrapped value (value) -> <o> wrapped value
value <*> Any value value <*> Any value
@*/ @*/
window.Ox = function(val) { global.Ox = function(val) {
return Ox.wrap(val); return Ox.wrap(val);
}; };
})(this);
/*@ /*@
Ox.load <f> Loads a module Ox.load <f> Loads a module
@ -255,11 +257,18 @@ Ox.loop = function() {
step = len == 4 ? arguments[2] : (start <= stop ? 1 : -1), step = len == 4 ? arguments[2] : (start <= stop ? 1 : -1),
fn = arguments[len - 1], fn = arguments[len - 1],
i; i;
try {
for (i = start; step > 0 ? i < stop : i > stop; i += step) { for (i = start; step > 0 ? i < stop : i > stop; i += step) {
if (fn(i) === false) { if (fn(i) === false) {
console.warn('Returning false in Ox.loop is deprecated.')
break; break;
} }
} }
} catch(e) {
if (e !== Ox.BreakError) {
throw e;
}
}
return i; return i;
}; };
@ -313,7 +322,6 @@ Ox.print <f> Prints its arguments to the console
> Ox.print('foo').split(' ').pop() > Ox.print('foo').split(' ').pop()
"foo" "foo"
@*/ @*/
Ox.print = function() { Ox.print = function() {
var args = Ox.toArray(arguments), var args = Ox.toArray(arguments),
date = new Date(); date = new Date();
@ -332,7 +340,6 @@ Ox.uid <f> Returns a unique id
> Ox.uid() != Ox.uid() > Ox.uid() != Ox.uid()
true true
@*/ @*/
Ox.uid = (function() { Ox.uid = (function() {
var uid = 0; var uid = 0;
return function() { return function() {
@ -354,7 +361,6 @@ Ox.wrap <f> Wraps a value so that one can directly call any Ox function on it
> Ox.wrap("foobar").value() > Ox.wrap("foobar").value()
"foobar" "foobar"
@*/ @*/
Ox.wrap = function(val, chained) { Ox.wrap = function(val, chained) {
// somewhat inspired by underscore.js // somewhat inspired by underscore.js
var wrapper = { var wrapper = {