var widget = function( options ) { this.variable = "asdasdasd"; this.widgetID = options.widgetID; widgetID = options.widgetID; this.load = function(){ $.post( 'api.php', { id:'123123', cmd:'asdasdas' }, this.parse ) }; this.parse = function( data, status ){ console.log( data ); console.log( 'Called with a callback'); console.log( widgetID ); //$( parent.node ).append( 'TEST TEST TEST TEST!!!' ); $( widgets[ widgetID ].node ).append( 'TET TETSET TEST TET '); }; this.node = $.DIV( {}, 'asdasdasdasd' ); parent = this; } //var firstW = new widget(); var widgets = []; console.log( widgets.length ); widgets.push( new widget( { widgetID: ( widgets.length ) } ) ); $( document ).ready( function(){ $( 'body' ).append( widgets[0].node ); widgets[0].load(); } );