Prototypes Object.extend with multiple objects that contain there own functions.

Posted by erickreutz on Stack Overflow See other posts from Stack Overflow or by erickreutz
Published on 2010-03-25T03:41:42Z Indexed on 2010/03/25 3:53 UTC
Read the original article Hit count: 310

How would I achieve something along the lines of this..

var Persistence = new Lawnchair('name');

Object.extend(Lawnchair.prototype, {
  UserDefaults: {
    setup: function(callback) {
                  // "save" is a native Lawnchair function that doesnt
                  //work because
                  // "this" does not reference "Lawnchair"
                  // but if I am one level up it does. Say if I defined
                  // a function called UserDefaults_setup() it would work
                  // but UserDefaults.setup does not work.
                  this.save({key: 'key', value: 'value'});


                // What is this functions scope?
                // How do I access Lawnchairs "this"
        }
    },

    Schedule: {
        refresh: function(callback) {

        }
    }
});

//this get called but doesnt work.
Persistence.UserDefaults.setup(); 

© Stack Overflow or respective owner

Related posts about prototype

Related posts about JavaScript