Skip to content

API design guidelines

Dave Methvin edited this page Mar 15, 2016 · 8 revisions

jQuery Core project guidelines:

  • Provide a set of APIs that work consistently across supported browsers.
  • Document exceptions where consistency is impractical or impossible.
  • Work with browser makers to make the web platform behave consistently.

jQuery API guidelines:

  • Avoid Boolean traps. - In particular, there should never be more than one Boolean value in an API signature. Booleans should be avoided in general, since they are not self-documenting.
  • Avoid global state. - APIs such as jQuery.ajaxSetup() affect behavior globally, making it difficult for a plugin author to depend on default values. We will avoid these types of APIs in the future.
  • Undocumented inputs result in unpredictable output. - The API may throw an error inside jQuery, do nothing, or have some unpredictable behavior. This may change without warning across versions, even minor patches.
  • Use .api(name) for getters and .api(name, value) for setters.
  • A getter on an empty jQuery collection returns undefined.

Clone this wiki locally