What does it do ?; jQuery.ui || (function ($) {

Possible duplicate:
What is the consequence of this javascript bit?

I was looking at the source code of the jQuery UI. I saw this line at the beginning of the js file:

;jQuery.ui || (function($) { 

what is he doing

(more from jquery.ui.core.js)

 /*! * jQuery UI 1.8 * * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://docs.jquery.com/UI */ ;jQuery.ui || (function($) { .ui = { version: "1.8", // $.ui.plugin is deprecated. Use the proxy pattern instead. plugin: { ... 
+4
source share
3 answers

Destruction:

 // make sure that any previous statements are properly closed // this is handy when concatenating files, for example ; // Call the jQuery.ui object, or, if it does not exist, create it jQuery.ui || (function($) { 
+1
source

Edit: Dupe What is the consequence of this javascript bit?

  • The leading semicolon is to make sure that any previous statements are closed when several source files have been indexed into one.

  • jQuery.ui || bit jQuery.ui || ensures that the following function is defined only if jQuery.ui does not already exist.

+2
source

javascript || will use the first value if it is considered true and will use the second if the first evaluates to false.

In this case, I assume that it checks if jQuery.ui exists, and if not, then it will evaluate the anonymous function. If jQuery.ui really exists, then || will not evaluate the second value, and therefore the anonymous function will not be launched.

+1
source

All Articles