[jQuery] Re: Am I using 'this' too often?
Are you using this: http://tablesorter.com ? Because it's quite easy to update: http://tablesorter.com/docs/example-ajax.html On nov. 10, 23:58, George [EMAIL PROTECTED] wrote: Thanks for the linkhttp://docs.jquery.com/UI/Developer_Guide You are absolutely right about understanding. Our professor of math was saying First you have to use it, then you will understand it. I found it to be very true. I had been using JQuery for some time... It's just I am working on a new project which requires the tablesorter plug-in functionality married with AJAX. Unfortunately I were not able to use tablesorter as is. Since data comes from AJAX and tablesorter plug in does not allow me reload data into grid easily. I spent some time with it trying to fit it in but finally gave up and decided that it's time to write my own thing. And that is how I realized that I know too little about modern JavaScript language. I used to think that I know it pretty well when in reality all I could do is to use alert and setInteval functions :) George. On Nov 10, 3:11 pm, Balazs Endresz [EMAIL PROTECTED] wrote: The thing with the other libraries is that jQuery mainly promotes writing a simple functional plugin, beacause in many cases object- oriented code is really not necessary. Of course in other cases it is, like when building a widget:http://docs.jquery.com/UI/Developer_Guide So I think if you want to write your application that doesn't need to be a jquery plugin, just use a general design pattern if that's more suitable. And most likely it will be convenient to write some custom jQuery plugins too, but that is really simple:http://docs.jquery.com/Plugins/Authoring Using jQuery should be very easy, and you don't have to understand it in depth first, just play with the examples and see what happens. Understanding how to construct a javascript application is quite a different thing. Of course they meet some time in the future, e.g. if you're building a complex jQuery plugin, but this shouldn't be the point to start I think, just start learning these separately! Cheers, Balazs On Nov 10, 7:24 pm, George [EMAIL PROTECTED] wrote: I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without
[jQuery] Re: Am I using 'this' too often?
you may want to have a look here http://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George
[jQuery] Re: Am I using 'this' too often?
I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
The plugin authoring page won't help you much building a class in javascript. If you want to use the this keyword less you can use private variables: http://javascript.crockford.com/private.html and there are some more great sources here: http://www.crockford.com/javascript/ But transforming a complex generic js class to a jQuery plugin is another story as a plugin should generally return a jQuery object. Some patterns regarding this issue came up here: http://groups.google.com/group/jquery-en/browse_thread/thread/9dc9be1cc298cbdd After reading the article on private variables it should be clear, but briefly the the problem is that if you don't use the this keyword then CheckPageIndex will be a reference to a variable in the closure (function) you use it, or if it doesn't exist there then it will be a global variable. And this way you don't have any closure that could remember the variable. So you need to define things in a closure (function). Anyway, it's much better explained in the article :) On Nov 10, 6:29 pm, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this pagehttp://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
The thing with the other libraries is that jQuery mainly promotes writing a simple functional plugin, beacause in many cases object- oriented code is really not necessary. Of course in other cases it is, like when building a widget: http://docs.jquery.com/UI/Developer_Guide So I think if you want to write your application that doesn't need to be a jquery plugin, just use a general design pattern if that's more suitable. And most likely it will be convenient to write some custom jQuery plugins too, but that is really simple: http://docs.jquery.com/Plugins/Authoring Using jQuery should be very easy, and you don't have to understand it in depth first, just play with the examples and see what happens. Understanding how to construct a javascript application is quite a different thing. Of course they meet some time in the future, e.g. if you're building a complex jQuery plugin, but this shouldn't be the point to start I think, just start learning these separately! Cheers, Balazs On Nov 10, 7:24 pm, George [EMAIL PROTECTED] wrote: I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text -
[jQuery] Re: Am I using 'this' too often?
Thanks for the link http://docs.jquery.com/UI/Developer_Guide You are absolutely right about understanding. Our professor of math was saying First you have to use it, then you will understand it. I found it to be very true. I had been using JQuery for some time... It's just I am working on a new project which requires the tablesorter plug-in functionality married with AJAX. Unfortunately I were not able to use tablesorter as is. Since data comes from AJAX and tablesorter plug in does not allow me reload data into grid easily. I spent some time with it trying to fit it in but finally gave up and decided that it's time to write my own thing. And that is how I realized that I know too little about modern JavaScript language. I used to think that I know it pretty well when in reality all I could do is to use alert and setInteval functions :) George. On Nov 10, 3:11 pm, Balazs Endresz [EMAIL PROTECTED] wrote: The thing with the other libraries is that jQuery mainly promotes writing a simple functional plugin, beacause in many cases object- oriented code is really not necessary. Of course in other cases it is, like when building a widget:http://docs.jquery.com/UI/Developer_Guide So I think if you want to write your application that doesn't need to be a jquery plugin, just use a general design pattern if that's more suitable. And most likely it will be convenient to write some custom jQuery plugins too, but that is really simple:http://docs.jquery.com/Plugins/Authoring Using jQuery should be very easy, and you don't have to understand it in depth first, just play with the examples and see what happens. Understanding how to construct a javascript application is quite a different thing. Of course they meet some time in the future, e.g. if you're building a complex jQuery plugin, but this shouldn't be the point to start I think, just start learning these separately! Cheers, Balazs On Nov 10, 7:24 pm, George [EMAIL PROTECTED] wrote: I see your point... I had discovered recently the lack of JavaScript knowledge. And since I mostly doing web development I realized that I am missing out a lot. Unfortunately the object oriented approach JavaScript using is different from other object oriented languages I know (C++, C#, Java) So I am trying to get up to speed with JavaScript and making up my own problems/tasks. Like I am learning how 'this' works with JavaScript... So the code I wrote is not promoted by another library :) It's promoted by my background in C++ and C# mostly :) So I chose JQuery as a library to use but before I can freely start using it I want to understand how things work. Cause as of right now if you tell me to write JQuery from scratch I will not be ably even to start :) And even having full source available does not help much since I often do not understand what is going on Thanks George. On Nov 10, 12:50 pm, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: Well, using the pattern for plugin creation will make your life easier, and this will make more sense. Reading your code, it feels like you are using the structuration promoted by another library On Mon, Nov 10, 2008 at 6:29 PM, George [EMAIL PROTECTED] wrote: I had looked there probably 10 times :) Are you implying that I need to convert my code to being Plug-In? Other than that I do not see how this page http://docs.jquery.com/Plugins/Authoring answers my question... Sorry, but please spell it out for me. The Plug-In would be the next step for me.. But as of now I am trying to nail down the use of 'this' in JavaScript as it's a bit different from what I am used to. George. On Nov 10, 11:43 am, Olivier Percebois-Garve [EMAIL PROTECTED] wrote: you may want to have a look herehttp://docs.jquery.com/Plugins/Authoring On Mon, Nov 10, 2008 at 5:20 PM, George [EMAIL PROTECTED] wrote: Being newbie in JavaScript I am trying to code my own helper object that does pagination. So here is a snippet of my code. MyData.prototype = { blablabla... PageUp: function() { this.iFrom += this.pageSize; this.CheckPageIndex(); }, CheckPageIndex: function() { if( this.iFrom = this.data.length ) this.iFrom = Math.floor((this.data.length - 1)/ this.pageSize) * this.pageSize; if( this.iFrom 0 ) this.iFrom = 0; } } Why do I need to call CheckPageIndex using this.CheckPageIndex when called from PageUp? It's in the same object... Without 'this' I get an error 'CheckPageIndex is undefined'. Coming from object oriented languages like C++ I have a trouble understanding it. Or am I doing it wrong and there is a way not to specify 'this' to many times? Thanks George- Hide quoted