Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4601986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:54:42+00:00 2026-05-21T23:54:42+00:00

What is considered the best way to handle misuse in a jQuery plugin —

  • 0

What is considered the best way to handle misuse in a jQuery plugin — ignore, or throw an error? In the situation I’m working with, I have a plugin that binds some functionality to an image. Once bound, you can do some other things through methods, e.g. set or get state information which can be changed by client interaction, e.g.:

$('selector').myPlugin();
$('selector').myPlugin('some-method',data);

What should one do when:

  • a selector contains no relevant elements (suspect the answer to this is, nothing, no error)
  • a method, which is only relevant to a previously bound element, is applied to a selector with no relevant elements
  • a method contains parameter data that is invalid

I feel like the right thing to do in some cases i just to ignore anything that’s invalid or doesn’t apply and proceed without errors. A big part of the “jQuery way” is to act in a predictable fashion as much as possible, which to me means, don’t break unless you have to.

On the other hand, this makes debugging more difficult, since you won’t ever get any errors when doing things you aren’t supposed to. Sometimes that could be reasonable (e.g., applying a plugin to a set of elements for which only a subset is relevant). On the other hand, doing things like trying to apply a specific method to an irrelevant element, or passing bad parameter data, could cause more trouble in the long run to ignore errors.

Is there any conventional wisdom on this? Add an “ignore-errors” option?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T23:54:43+00:00Added an answer on May 21, 2026 at 11:54 pm

    On bullet 1 if you are following the patterns on this page http://docs.jquery.com/Plugins/Authoring, you are doing the right thing. Namely this:

    var methods = {
    init : function( options ) {

       return this.each(function(){
    

    On bullet 3 ignore parameter names that you don’t use. Throw an exception when they use bad data in one of your parameters. This will I believe stop all processing of matched items in the selector. You could also provide a debug mode where it will throw the exception. This way they can turn it on during testing and leave it off when they go into production.

    On bullet 2 I’m tempted to say go with what you picked out of what I said for bullet 3. If it is something like getting data associated with an element that hasn’t had a setXXXX called, just return an empty set of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in Cocoa that is currently considered best practice for creating
What is the best way to handle a link that has a video within
Three SHA512Managed related questions: Is SHA512Managed considered the best one-way hash available in .NET
It's widely considered that the best reason to validate one's HTML is to ensure
What is the 'best' way to handle the html markup for partial views? (which
What is considered the best way of handling multiple NSTableViews without using Cocoa Bindings?
What is the best way to handle temporary objects in Core Data? I've seen
What is the simplest/cleanest/easiest/best way to handle Null value of a Strongly Typed DataSet
What's the best way to handle random number generation in Haskell (or what are
I am trying to figure out what is the best way to handle dependencies

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.