Skip to content

Instantly share code, notes, and snippets.

@re5et
Created July 3, 2012 01:00
Show Gist options
  • Select an option

  • Save re5et/3036720 to your computer and use it in GitHub Desktop.

Select an option

Save re5et/3036720 to your computer and use it in GitHub Desktop.

Revisions

  1. re5et revised this gist Jul 3, 2012. 1 changed file with 15 additions and 15 deletions.
    30 changes: 15 additions & 15 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,13 @@ var GlobalVars = function(){};

    GlobalVars.prototype.cacheVars = function(){
    this.cache = {};
    for(prop in window){
    for(var prop in window){
    this.cache[prop] = window[prop];
    }
    };

    GlobalVars.prototype.diff = function(){
    for(prop in window){
    for(var prop in window){
    // it is the same
    if(window[prop] === this.cache[prop]){
    continue;
    @@ -27,7 +27,7 @@ GlobalVars.prototype.diff = function(){
    }
    }
    // check for delete properties
    for(prop in this.cache){
    for(var prop in this.cache){
    // it was deleted
    if(this.cache[prop] !== undefined && window[prop] === undefined){
    console.log('window.'+prop+' was deleted!');
    @@ -37,15 +37,15 @@ GlobalVars.prototype.diff = function(){

    // Use like:
    //
    // var vars = new GlobalVars();
    //
    // window.foo = 'bar'
    // window.bar = 'baz'
    //
    // vars.cacheVars();
    //
    // window.qux = 1;
    // window.foo = function(){console.log('baz')};
    // delete window.bar;
    //
    // vars.diff();
    var vars = new GlobalVars();

    window.foo = 'bar'
    window.bar = 'baz'

    vars.cacheVars();

    window.qux = 1;
    window.foo = function(){console.log('baz')};
    delete window.bar;

    vars.diff();
  2. re5et revised this gist Jul 3, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,7 @@ GlobalVars.prototype.diff = function(){
    }
    }
    // check for delete properties
    for(var prop in this.cache){
    for(prop in this.cache){
    // it was deleted
    if(this.cache[prop] !== undefined && window[prop] === undefined){
    console.log('window.'+prop+' was deleted!');
  3. re5et revised this gist Jul 3, 2012. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,21 @@
    var GlobalVars = function(){}
    var GlobalVars = function(){};

    GlobalVars.prototype.cacheVars = function(){
    this.cache = {}
    for(var prop in window){
    this.cache = {};
    for(prop in window){
    this.cache[prop] = window[prop];
    }
    }
    };

    GlobalVars.prototype.diff = function(){
    for(var prop in window){
    for(prop in window){
    // it is the same
    if(window[prop] == this.cache[prop]){
    if(window[prop] === this.cache[prop]){
    continue;
    }
    else{
    // it has changed
    if(this.cache[prop] && window[prop] != this.cache[prop]){
    if(this.cache[prop] && window[prop] !== this.cache[prop]){
    console.log('window.'+prop+' changed from: '+this.cache[prop]+' to: '+window[prop] + '!');
    }
    else{
    @@ -29,11 +29,11 @@ GlobalVars.prototype.diff = function(){
    // check for delete properties
    for(var prop in this.cache){
    // it was deleted
    if(this.cache[prop] != undefined && window[prop] == undefined){
    if(this.cache[prop] !== undefined && window[prop] === undefined){
    console.log('window.'+prop+' was deleted!');
    }
    }
    }
    };

    // Use like:
    //
  4. re5et revised this gist Jul 3, 2012. 1 changed file with 24 additions and 24 deletions.
    48 changes: 24 additions & 24 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -9,30 +9,30 @@ GlobalVars.prototype.cacheVars = function(){

    GlobalVars.prototype.diff = function(){
    for(var prop in window){
    // it is the same
    if(window[prop] == this.cache[prop]){
    continue;
    }
    else{
    // it has changed
    if(this.cache[prop] && window[prop] != this.cache[prop]){
    console.log('window.'+prop+' changed from: '+this.cache[prop]+' to: '+window[prop] + '!');
    }
    else{
    // it is new
    if(window[prop] && !this.cache[prop]){
    console.log('window.'+prop+' was introduced! Value is: '+window[prop]);
    }
    }
    }
    }
    // check for delete properties
    for(var prop in this.cache){
    // it was deleted
    if(this.cache[prop] != undefined && window[prop] == undefined){
    console.log('window.'+prop+' was deleted!');
    }
    }
    // it is the same
    if(window[prop] == this.cache[prop]){
    continue;
    }
    else{
    // it has changed
    if(this.cache[prop] && window[prop] != this.cache[prop]){
    console.log('window.'+prop+' changed from: '+this.cache[prop]+' to: '+window[prop] + '!');
    }
    else{
    // it is new
    if(window[prop] && !this.cache[prop]){
    console.log('window.'+prop+' was introduced! Value is: '+window[prop]);
    }
    }
    }
    }
    // check for delete properties
    for(var prop in this.cache){
    // it was deleted
    if(this.cache[prop] != undefined && window[prop] == undefined){
    console.log('window.'+prop+' was deleted!');
    }
    }
    }

    // Use like:
  5. re5et created this gist Jul 3, 2012.
    51 changes: 51 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    var GlobalVars = function(){}

    GlobalVars.prototype.cacheVars = function(){
    this.cache = {}
    for(var prop in window){
    this.cache[prop] = window[prop];
    }
    }

    GlobalVars.prototype.diff = function(){
    for(var prop in window){
    // it is the same
    if(window[prop] == this.cache[prop]){
    continue;
    }
    else{
    // it has changed
    if(this.cache[prop] && window[prop] != this.cache[prop]){
    console.log('window.'+prop+' changed from: '+this.cache[prop]+' to: '+window[prop] + '!');
    }
    else{
    // it is new
    if(window[prop] && !this.cache[prop]){
    console.log('window.'+prop+' was introduced! Value is: '+window[prop]);
    }
    }
    }
    }
    // check for delete properties
    for(var prop in this.cache){
    // it was deleted
    if(this.cache[prop] != undefined && window[prop] == undefined){
    console.log('window.'+prop+' was deleted!');
    }
    }
    }

    // Use like:
    //
    // var vars = new GlobalVars();
    //
    // window.foo = 'bar'
    // window.bar = 'baz'
    //
    // vars.cacheVars();
    //
    // window.qux = 1;
    // window.foo = function(){console.log('baz')};
    // delete window.bar;
    //
    // vars.diff();