var objectTest = {
arr: [1,3,4,6,7,7,7,45,3]
}
function addMethod(object, name, fn) {
var oldObject = object[name];
object[name] = function() {
if (fn.length === arguments.length) return fn.apply(this, arguments)
if (typeof oldObject === 'function') return oldObject.apply(this, arguments);
}
}
addMethod(objectTest, "findTest", find0);
addMethod(objectTest, "findTest", find1);
addMethod(objectTest, "findTest", find2);
function find0() {
return this.arr;
}
function find1(idx) {
return this.arr[idx];
}
function find2(st, ed) {
return this.arr.slice(st, ed);
}
console.dir(objectTest.findTest)
console.log(objectTest.findTest())
console.log(objectTest.findTest(4))
console.log(objectTest.findTest(1,4))
console.log(arr.findTest(1,4,7))
console