/** * DEVELOPED BY * GIL LOPES BUENO * gilbueno.mail@gmail.com * * WORKS WITH: * IE 9+, FF 4+, SF 5+, WebKit, CH 7+, OP 12+, BESEN, Rhino 1.7+ * * FORK: * https://gist.github.com/1627705 */ var $watchjs$ = { isFunction: function(functionToCheck) { var getType = {}; return functionToCheck && getType.toString.call(functionToCheck) == '[object Function]'; }, isInt: function(x) { var y = parseInt(x); if (isNaN(y)) return false; return x == y && x.toString() == y.toString(); }, isArray: function(obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }, defineGetAndSet: function(obj, propName, getter, setter){ try{ Object.defineProperty(obj, propName, { get: getter, set: setter, enumerable: true, configurable: true }); }catch(error){ try{ Object.prototype.__defineGetter__.call(obj, propName, getter); Object.prototype.__defineSetter__.call(obj, propName, setter); }catch(error2){ throw "watchJS error: browser not supported :/" } } }, defineProp: function(obj, propName, value){ try{ Object.defineProperty(obj, propName, { enumerable: false , configurable: true , writable: false , value: value }); }catch(error){ obj[propName] = value; } } }; $watchjs$.defineProp(Object.prototype, "watch", function() { if (arguments.length == 1) this.watchAll.apply(this, arguments); else if ($watchjs$.isArray(arguments[0])) this.watchMany.apply(this, arguments); else this.watchOne.apply(this, arguments); }); $watchjs$.defineProp(Object.prototype, "watchAll", function(watcher) { var obj = this; if (obj instanceof String || (!(obj instanceof Object) && !$watchjs$.isArray(obj))) //accepts only objects and array (not string) return; var props = []; if($watchjs$.isArray(obj)){ for (var prop=0; prop