rename vars

This commit is contained in:
rolux 2012-05-25 09:34:50 +02:00
parent 61bb1c3598
commit 26093367ec

View file

@ -10,25 +10,27 @@ Some conventions:
Variable names
arg argument
args arguments
arr array
array array
canFoo boolean
callback callback function
col collection (array, string or object)
collection collection (array, string or object)
date date
fn function
iterator iterator function
hasFoo boolean
i index (integer key)
index index (integer key)
isFoo boolean
k key (of a key/value pair)
key key (of a key/value pair)
max maximum value
min minimum value
num number
obj object
re regexp
number number
object object
regexp regexp
ret return value
test test function
v value (of a key/value pair)
val value (of a key/value pair)
value value (of a key/value pair)
Indentation
Variable definitions
var a = {
@ -78,8 +80,8 @@ Some conventions:
(value) -> <o> wrapped value
value <*> Any value
@*/
global.Ox = function(val) {
return Ox.wrap(val);
global.Ox = function(value) {
return Ox.wrap(value);
};
})(this);
@ -90,7 +92,7 @@ Ox.Break = function() {
throw Ox.BreakError;
};
Ox.BreakError = new SyntaxError('Illegal Ox.Break()() statement');
Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement');
/*@
Ox.load <f> Loads a module
@ -121,12 +123,15 @@ Ox.load = function() {
}
length = Ox.len(modules);
Ox.forEach(modules, function(options, module) {
Ox.loadFile(Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js', function() {
Ox.load[module](options, function(s) {
success += s;
++counter == length && callback(success == counter);
});
});
Ox.loadFile(
Ox.PATH + 'Ox.' + module + '/Ox.' + module + '.js',
function() {
Ox.load[module](options, function(s) {
success += s;
++counter == length && callback(success == counter);
});
}
);
});
};
@ -144,13 +149,13 @@ Ox.localStorage = function(namespace) {
if (!window.localStorage) {
window.localStorage = {};
}
function storage(key, val) {
var args, ret, value;
function storage(key, value) {
var args, ret;
if (arguments.length == 0) {
ret = {};
Ox.forEach(localStorage, function(val, key) {
Ox.forEach(localStorage, function(value, key) {
if (Ox.startsWith(key, namespace + '.')) {
ret[key.slice(namespace.length + 1)] = JSON.parse(val);
ret[key.slice(namespace.length + 1)] = JSON.parse(value);
}
});
} else if (arguments.length == 1 && typeof key == 'string') {
@ -159,8 +164,8 @@ Ox.localStorage = function(namespace) {
ret = value === void 0 ? void 0 : JSON.parse(value);
} else {
args = Ox.makeObject(arguments);
Ox.forEach(args, function(val, key) {
localStorage[namespace + '.' + key] = JSON.stringify(val);
Ox.forEach(args, function(value, key) {
localStorage[namespace + '.' + key] = JSON.stringify(value);
});
ret = this;
}
@ -168,9 +173,7 @@ Ox.localStorage = function(namespace) {
};
// IE 8 doesn't like `storage.delete`
storage['delete'] = function(key) {
var keys = arguments.length == 0
? Object.keys(storage())
: [key];
var keys = arguments.length == 0 ? Object.keys(storage()) : [key];
keys.forEach(function(key) {
delete localStorage[namespace + '.' + key];
});
@ -194,16 +197,16 @@ Ox.Log = (function() {
}
return ret;
};
that.filter = function(val) {
if (!Ox.isUndefined(val)) {
that.filter = function(value) {
if (!Ox.isUndefined(value)) {
that.filter.enable();
log.filter = Ox.makeArray(val);
log.filter = Ox.makeArray(value);
storage('log', log);
}
return log.filter;
};
that.filter.add = function(val) {
return that.filter(Ox.unique(log.filter.concat(Ox.makeArray(val))));
that.filter.add = function(value) {
return that.filter(Ox.unique(log.filter.concat(Ox.makeArray(value))));
};
that.filter.disable = function() {
log.filterEnabled = false;
@ -213,10 +216,10 @@ Ox.Log = (function() {
log.filterEnabled = true;
storage('log', log);
};
that.filter.remove = function(val) {
val = Ox.makeArray(val);
that.filter.remove = function(value) {
value = Ox.makeArray(value);
return that.filter(log.filter.filter(function(v) {
return val.indexOf(v) == -1;
return value.indexOf(v) == -1;
}));
};
that.log = function() {
@ -255,28 +258,28 @@ Ox.loop <f> For-loop, functional-style
step <n> Step value
fn <f> Iterator function
i <n> Counter value
> Ox.loop(10, function(i) { i == 4 && Ox.Break()() })
> Ox.loop(10, function(i) { i == 4 && Ox.Break() })
4
> Ox.loop(0, 3, 2, function() {})
4
@*/
Ox.loop = function() {
var len = arguments.length,
start = len > 2 ? arguments[0] : 0,
stop = arguments[len > 2 ? 1 : 0],
step = len == 4 ? arguments[2] : (start <= stop ? 1 : -1),
fn = arguments[len - 1],
var length = arguments.length,
start = length > 2 ? arguments[0] : 0,
stop = arguments[length > 2 ? 1 : 0],
step = length == 4 ? arguments[2] : (start <= stop ? 1 : -1),
iterator = arguments[length - 1],
i;
try {
for (i = start; step > 0 ? i < stop : i > stop; i += step) {
// fn(i);
if (fn(i) === false) {
// iterator(i);
if (iterator(i) === false) {
throw new Error('Returning false in Ox.loop is deprecated.');
}
}
} catch(e) {
if (e !== Ox.BreakError) {
throw e;
} catch (error) {
if (error !== Ox.BreakError) {
throw error;
}
}
return i;
@ -295,9 +298,7 @@ Ox.print = function() {
var args = Ox.toArray(arguments),
date = new Date();
args.unshift(
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)/*,
(arguments.callee.caller && arguments.callee.caller.name)
|| '(anonymous)'*/
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().slice(-3)
);
window.console && window.console.log.apply(window.console, args);
return args.join(' ');
@ -330,7 +331,7 @@ 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) {
Ox.wrap = function(value, chained) {
// somewhat inspired by underscore.js
var wrapper = {
chain: function() {
@ -339,7 +340,7 @@ Ox.wrap = function(val, chained) {
},
chained: chained || false,
value: function() {
return val;
return value;
}
};
Object.getOwnPropertyNames(Ox).forEach(function(name) {
@ -350,7 +351,7 @@ Ox.wrap = function(val, chained) {
) {
wrapper[name] = function() {
var args = Array.prototype.slice.call(arguments), ret;
args.unshift(val);
args.unshift(value);
ret = Ox[name].apply(Ox, args);
return wrapper.chained ? Ox.wrap(ret, true) : ret;
};