Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.observe(i, function(b){ b.object[change.name] > b.type ? console.log('decreased') : console.log('increased'); });
- var i = 4;
- var a = i;
- setInterval(function()
- {
- if(i != a) a > i ? console.log('decreased') : console.log('increased');
- }, 1000);
- i = 10;
- var i = {i:5};
- i.watch("i", function (id, oldval, newval) {
- newval > oldval ? console.log('decreased') : console.log('increased');
- return newval;
- });
- if (!Object.prototype.watch) {
- Object.defineProperty(Object.prototype, "watch", {
- enumerable: false
- , configurable: true
- , writable: false
- , value: function (prop, handler) {
- var
- oldval = this[prop]
- , newval = oldval
- , getter = function () {
- return newval;
- }
- , setter = function (val) {
- oldval = newval;
- return newval = handler.call(this, prop, oldval, val);
- }
- ;
- if (delete this[prop]) { // can't watch constants
- Object.defineProperty(this, prop, {
- get: getter
- , set: setter
- , enumerable: true
- , configurable: true
- });
- }
- }
- });
- }
- // object.unwatch
- if (!Object.prototype.unwatch) {
- Object.defineProperty(Object.prototype, "unwatch", {
- enumerable: false
- , configurable: true
- , writable: false
- , value: function (prop) {
- var val = this[prop];
- delete this[prop]; // remove accessors
- this[prop] = val;
- }
- });
- }
- i = 4;
- function setValue(obj, val)
- {
- val < obj ? console.log('decrease') : console.log('increase');
- obj = val;
- }
- setValue(i, 10);
- var triggerVariable;
- function changeVariable(newVal){
- if(triggerVariable !== newVal){
- triggerVariable = newVal;
- callFunction();
- }
- }
- function callFunction(){
- alert('variable changed!');
- }
- changeVariable(10);
- function specVal (value)
- {
- this.onChange = null;
- this.value = value;
- this.val = function()
- {
- return this.value;
- };
- this.add = function(i)
- {
- this.value += i;
- if (this.onChange != null)
- this.onChange(this);
- return this;
- }
- }
- function somethingChanged(val)
- {
- alert('changed: ' + val.val());
- }
- myValue = new specVal(10);
- myValue.onChange = somethingChanged;
- myValue.add(5);
- myValue.add(4);
- Function setMyVar(val){
- if(_myVar !== val){
- _myVar = val;
- $('#anyelement').triggerHandler('myvarupdated', [myVar]);
- }
- }
- var lastValue = 0;
- $(function () {
- if (lastValue > originalValue){
- console.log ("Increasing");
- }
- else if (lastValue < originalValue) {
- console.log("Decreasing");
- }
- lastValue = originalValue;
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement