There seems to be a missing brace in there. ANyway, try this:

$.extend(MyObject.prototype, {

        save: function(id)
        {
                var self = this;
                var html="some html";
                
                $.post(
                        'post_page.php',
                        {'id':id, 'c':html},
                        function(data)
                        {
                                self.save_complete(data.div_id, data.content);
                        },
                        'json'
                );
        },
        
        save_complete: function( id, content )
        {
                alert( "saved: " + id );
        }
});


On Fri, Jan 16, 2009 at 9:16 PM, puppycrack <puppycr...@gmail.com> wrote:
>
> I am having a problem with an Object using closures, and referencing
> the "this" reference from within the closure.
>
> $.extend(MyObject.prototype, {
>        save: function(id) {
>                var html="some html";
>                $.post( 'post_page.php', {'id':id, 'c':html},
>                        function(data) {
>                                this.save_complete(data.div_id, data.content);
>                        }, 'json');
>
>        save_complete: function( id, content ) {
>                alert( "saved: " + id );
>        }
> });
>
> If I call save() on this object, and the AJAX call happens, the "this"
> reference does not refer to the instance of MyObject - which is what
> I'm trying to do.  Is there any way around this?
>
> Thanks!
>
> - pc
>

Reply via email to