HighDots Forums  

Plugin Authoring Code Example Incorrect

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss Plugin Authoring Code Example Incorrect in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Shane Riley
 
Posts: n/a

Default Plugin Authoring Code Example Incorrect - 11-07-2009 , 07:19 AM






I created a jQuery plugin for the sake of learning the process and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using jQuery
chaining. However the code example above has the return this statement
at the end of the plugin function rather than the each method. While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.

Reply With Quote
  #2  
Old   
Morten Maxild
 
Posts: n/a

Default Re: [jQuery] Plugin Authoring Code Example Incorrect - 11-07-2009 , 11:43 AM






'return true' is wrong, you need to return the 'wrapped set' to support chaining. The $().each method does return the 'wrapped set' and you can take advantage of this.

HTH
Morten


Quote:
-----Original Message-----
From: Shane Riley [mailto:shanerileydotinfo (AT) gmail (DOT) com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using jQuery
chaining. However the code example above has the return this statement
at the end of the plugin function rather than the each method. While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.

Reply With Quote
  #3  
Old   
Shane Riley
 
Posts: n/a

Default Re: Plugin Authoring Code Example Incorrect - 11-08-2009 , 12:44 PM



I ended up using this syntax instead:
return this.each(function(){});

On Nov 7, 11:43*am, "Morten Maxild" <mmax... (AT) gmail (DOT) com> wrote:
Quote:
'return true' is wrong, you need to return the 'wrapped set' to support chaining. The $().each method does return the 'wrapped set' and you can take advantage of this.

HTH
Morten



-----Original Message-----
From: Shane Riley [mailto:shanerileydoti... (AT) gmail (DOT) com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using jQuery
chaining. However the code example above has the return this statement
at the end of the plugin function rather than the each method. While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.

Reply With Quote
  #4  
Old   
Morten Maxild
 
Posts: n/a

Default Re: [jQuery] Re: Plugin Authoring Code Example Incorrect - 11-08-2009 , 12:56 PM



Exactly...looks correct:-)

Quote:
-----Original Message-----
From: Shane Riley [mailto:shanerileydotinfo (AT) gmail (DOT) com]
Sent: Sunday, November 08, 2009 6:44 PM
To: jQuery (English)
Subject: [jQuery] Re: Plugin Authoring Code Example Incorrect

I ended up using this syntax instead:
return this.each(function(){});

On Nov 7, 11:43 am, "Morten Maxild" <mmax... (AT) gmail (DOT) com> wrote:
'return true' is wrong, you need to return the 'wrapped set' to support
chaining. The $().each method does return the 'wrapped set' and you can
take advantage of this.

HTH
Morten



-----Original Message-----
From: Shane Riley [mailto:shanerileydoti... (AT) gmail (DOT) com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using jQuery
chaining. However the code example above has the return this statement
at the end of the plugin function rather than the each method. While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.

Reply With Quote
  #5  
Old   
Karl Swedberg
 
Posts: n/a

Default Re: [jQuery] Re: Plugin Authoring Code Example Incorrect - 11-08-2009 , 01:13 PM



In the meantime, I changed the wording on that page.

Both of the following will work:
1)
return this.each(function() { /* do something */ });
2)
this.each(function() { /* do something */ });
return this;

--Karl

On Nov 8, 2009, at 12:56 PM, Morten Maxild wrote:

Quote:
Exactly...looks correct:-)

-----Original Message-----
From: Shane Riley [mailto:shanerileydotinfo (AT) gmail (DOT) com]
Sent: Sunday, November 08, 2009 6:44 PM
To: jQuery (English)
Subject: [jQuery] Re: Plugin Authoring Code Example Incorrect

I ended up using this syntax instead:
return this.each(function(){});

On Nov 7, 11:43 am, "Morten Maxild" <mmax... (AT) gmail (DOT) com> wrote:
'return true' is wrong, you need to return the 'wrapped set' to
support
chaining. The $().each method does return the 'wrapped set' and you
can
take advantage of this.

HTH
Morten



-----Original Message-----
From: Shane Riley [mailto:shanerileydoti... (AT) gmail (DOT) com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process
and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using
jQuery
chaining. However the code example above has the return this
statement
at the end of the plugin function rather than the each method.
While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true
in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.

Reply With Quote
  #6  
Old   
Shane Riley
 
Posts: n/a

Default Re: [jQuery] Re: Plugin Authoring Code Example Incorrect - 11-08-2009 , 01:20 PM



Thanks Karl. Turns out both worked for me, but I had placed the return
just outside the plugin function instead of within it.


On Nov 8, 2009, at 1:13 PM, Karl Swedberg wrote:

Quote:
In the meantime, I changed the wording on that page.

Both of the following will work:
1)
return this.each(function() { /* do something */ });
2)
this.each(function() { /* do something */ });
return this;

--Karl

On Nov 8, 2009, at 12:56 PM, Morten Maxild wrote:

Exactly...looks correct:-)

-----Original Message-----
From: Shane Riley [mailto:shanerileydotinfo (AT) gmail (DOT) com]
Sent: Sunday, November 08, 2009 6:44 PM
To: jQuery (English)
Subject: [jQuery] Re: Plugin Authoring Code Example Incorrect

I ended up using this syntax instead:
return this.each(function(){});

On Nov 7, 11:43 am, "Morten Maxild" <mmax... (AT) gmail (DOT) com> wrote:
'return true' is wrong, you need to return the 'wrapped set' to
support
chaining. The $().each method does return the 'wrapped set' and
you can
take advantage of this.

HTH
Morten



-----Original Message-----
From: Shane Riley [mailto:shanerileydoti... (AT) gmail (DOT) com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process
and got
it working no problem. In the plugin authoring docs it says that
if
you return true inside the each method, you can continue using
jQuery
chaining. However the code example above has the return this
statement
at the end of the plugin function rather than the each method.
While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true
in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.