in Ox.extend, use Ox.slice; add includePrototype argument to Ox.methods

This commit is contained in:
rolux 2012-05-21 22:04:22 +02:00
parent f83d317407
commit 75558d4b9d

View file

@ -6,7 +6,7 @@ Ox.extend <function> Extends an object with one or more other objects
{a: 1, b: 2, c: 3}
@*/
Ox.extend = function(obj) {
Ox.forEach(Array.prototype.slice.call(arguments, 1), function(arg, i) {
Ox.forEach(Ox.slice(arguments, 1), function(arg, i) {
Ox.forEach(arg, function(val, key) {
obj[key] = val;
});
@ -39,8 +39,17 @@ Ox.methods <f> Returns a sorted list of all method names of an object
> Ox.methods({a: [], b: false, f: function() {}, n: 0, o: {}, s: ''})
['f']
@*/
Ox.methods = function(obj) {
return Object.keys(obj).filter(function(key) {
Ox.methods = function(obj, includePrototype) {
var key, keys;
if (includePrototype) {
keys = [];
for (var key in obj) {
keys.push(key);
}
} else {
keys = Object.keys(obj);
}
return keys.filter(function(key) {
return Ox.isFunction(obj[key]);
}).sort();
};