这是如何工作的呢?Type = Type || 'any';
How does this work? type = type || 'any';
谁能解释一下这个表达式是如何工作的?
type = type || 'any';
这是否意味着如果类型未定义使用'any'?
如果type
为" false "(即false
,或undefined
或空字符串或null或未定义),则使用"any"
如果变量type
为假值,则设置为字符串'any'
,否则设置为自己的值
这是true OR alternative
条件。更简洁,基本上。
测试一下:http://jsfiddle.net/AlienWebguy/ussBZ/3/
var type = 0;
type = type || 'any';
alert('0 = ' + type); // alerts 0 = any
type = 1;
type = type || 'any';
alert('1 = ' + type); // alerts 1 = 1
type = true;
type = type || 'any';
alert('true = ' + type); // alerts true = true
type = false;
type = type || 'any';
alert('false = ' + type); // alerts false = any
type = 'foobar';
type = type || 'any';
alert('foobar = ' + type); // alerts foobar = foobar
type = '';
type = type || 'any';
alert(''''' = ' + type); // alerts '' = any
type = null;
type = type || 'any';
alert('null = ' + type); // alerts null = any
type = new Array();
type = type || 'any';
alert('new Array() = ' + type); // alerts new Array() =
type = [];
type = type || 'any';
alert('[] ' + type); // alerts [] =
type = {};
type = type || 'any';
alert('{} = ' + type); // alerts {} = [object Object]
type = new Object;
type = type || 'any';
alert('new Object = ' + type); // alerts new Object = [object Object]
这意味着,如果type计算结果为false,则使用'any'。即如果type为undefined, false, 0,…
相关文章:
- 如何将输入(type=text)从html表单传递到javascript函数
- 正在将base64 jpeg从input-type=file上传到服务器
- Typescript angularjs$http获取响应类型(避免使用<any>)
- 类型错误'未定义'不是对象(正在评估'navigator.connection.type'
- <输入id=“;“到期”;type=“;月份;min=“;2016-05”>如何填写“;min”;属性与当前
- angular type=[number]指令来阻止粘贴
- 节点,express应用程序返回text/javascript响应头(Content-Type),尽管设置了applic
- 未捕获错误:语法错误,无法识别的表达式:input[@type=submit]
- 如何停止向上滚动<按钮dojoType=“;dijit.form.Button”;type=“;提交”/>在
- type=text/javascript和language=javascript之间的区别
- jQuery$.post TypeError:e.type不是函数
- 当我使用JS/jQuery/any插件点击图像时,我如何使背景变暗+不可点击,并放大和居中我的图像
- X-Content-Type-Options=nosniff解决方法
- 为什么Angularjs验证don't与输入[type=“number”]一起工作
- Jasmine .calls.count and .calls.any throwing error
- 如何将按钮的数据属性设置为输入[type=text]中设置的任何值
- 有没有什么方法可以通过输入字段(type=file)来找出选择了多少个文件
- 当我将 GET /any 发送到自定义路由“GET /:id”时,我得到 req.params.id = 'favico
- 使用图像而不是文本(script type=“text/javascript”)
- 这是如何工作的呢?Type = Type || 'any';