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