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)
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
(function(global) {
/*@
Ox <f> The <code>Ox</code> object
See <code>Ox.wrap</code> for details.
(value) -> <o> wrapped value
value <*> Any value
@*/
window.Ox = function(val) {
global.Ox = function(val) {
return Ox.wrap(val);
};
})(this);
/*@
Ox.load <f> Loads a module
@ -255,11 +257,18 @@ Ox.loop = function() {
step = len == 4 ? arguments[2] : (start <= stop ? 1 : -1),
fn = arguments[len - 1],
i;
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 <f> 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 <f> Returns a unique id
> Ox.uid() != Ox.uid()
true
@*/
Ox.uid = (function() {
var uid = 0;
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()
"foobar"
@*/
Ox.wrap = function(val, chained) {
// somewhat inspired by underscore.js
var wrapper = {