Hello

Recently I've been trying to use ON with jQuery. I met with obstacle.
I couldn't use "this" keyword in certain cases to get my main object
reference...

//============================

var myObject = {

        layout: { 'align': '' },
        start: function() {
                $('form').bind('submit', this.buildLayout);     //WORKS
        },

        buildLayout: function() {
                this.layout.align = $('#elem').attr('value');   //DOESN'T WORK
        }
}

function initialize() {
        myObject.start();
}

$().ready(initialize);

//============================

As you can see from comments, I can pass this to bind(), but calling
it fails in function I bound. Instead of this.layout.align I have to
use myObject.layout.align...

As I comprehend, it's because jQuery uses "this" in event handlers, to
get reference of object where event occured. So in buildLayout "this"
points on "form". Is there any way to use bind() (and other jQuery
functions) and use this?

I can always use myObject.property.property, but I think that I
shouldn't make myself dependent on object's name...

Do you have any solution? Thanks is advance for tips.

PS: This is my first message to discussion group ever, I hope I do
everything ok.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to