这个javascript的结果是什么? [英] What is the consequence of this bit of javascript?

查看:143
本文介绍了这个javascript的结果是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看jQuery UI代码,我发现每个文件都以这样的结构开头:

I was looking at jQuery UI code, and I found that every file starts with a construct like this:

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

我的问题是:为什么在 jQuery ,为什么逻辑OR正在完成?

My question is: why is there a semicolon before jQuery, and why is the logical OR being done?

jrh

推荐答案


为什么jQuery之前有分号?

why is there a semicolon before jQuery?

半-colon用于确保安全的文件串联。(库和库组件经常打包到一个文件中)

The semi-colon is there to ensure safe file concatenation. (libraries and library components are frequently packed into a single file)


为什么逻辑OR正在完成?

why is the logical OR being done?

右侧的自动调用匿名函数只有在左侧的情况下才能运行语句评估为falsey值。因此,如果页面上已经存在 jQuery.ui ,则该函数将不会运行。它仅在 jQuery.ui 尚不存在。

The self-invoking anonymous function on the right hand-side will only run if the left-hand-side of the statement evaluates to a falsey value. So if jQuery.ui already exists on the page then the function will not run. It only runs when jQuery.ui does not yet exist.

这篇关于这个javascript的结果是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆