On 05/02/2007, at 2:04 PM, [EMAIL PROTECTED] wrote:
> 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/
>

Hello and welcome,

I believe that you can not make other instances of objects  
constructed like this anyway, so I don't see a problem with being  
dependent on the object's name. I use Object Notation to organise my  
jQuery code myself, but if I was planning on creating instances of an  
object as if it was a class (and therefore need my handlers to be  
more generic) then I would use prototype style object-oriented code  
instead.

I could be wrong though - I'm no guru - but it's something to consider.

Joel Birch.

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

Reply via email to