Possible Duplicate:
What does var x = x || {} ;
我在js中有这种界限,这只是简单明了,但并不确定最后一部分——<代码>(毒性->>>(<<>>>>>>>。
var xin = (function (name) {return name;}(xin || {}));
我的理解是,毒性是一种物体构造,现在我可以制造有毒物体。 <代码>新谢>,<>。 请允许我向大家介绍,感谢
Possible Duplicate:
What does var x = x || {} ;
我在js中有这种界限,这只是简单明了,但并不确定最后一部分——<代码>(毒性->>>(<<>>>>>>>。
var xin = (function (name) {return name;}(xin || {}));
我的理解是,毒性是一种物体构造,现在我可以制造有毒物体。 <代码>新谢>,<>。 请允许我向大家介绍,感谢
xin || {}
这与:
xin ? xin : {};
或更长期的形式:
if(xin) {
return xin;
}
else {
return {};
}
<代码>>>。
表达
var x = x OR {};
届时应当变得更加明显。
如果x
有falsy数值(如null
,un specified/code>0
,><>>>>
,则仅保留现值。 如此之长的版本就象这样。
var x = x ? x : {};
{><>>>/代码>);
例如:
var name = xin || {};
这一点已转化为:
if(xin)
var name = xin;
else
name = {};
在javascript中,你可以使用有条件的操作者( >/code>和<&&
)来制作表述。 例如:
typeof f === function && ((arguments.length == 0 && f()) || f.apply({},arguments)) || g();
这一表述可翻译成以下文字:
if(typeof f === function )
{
if(arguments.length == 0)
f();
else
f.apply({},arguments);
}
else
g();
不管怎么说,这只是为了去掉目的,你竟然使用与有条件的操作者一起建造的大型nes词,因为它非常无法读(很难维持)。
这种表述经常用于初始化,如果已经存在的话,你不想超越某种价值。 一个很好的例子就是在多个js档案中使用一个名称空间。 采用这一技术(var namespace = namespace ±>>;
如果毒素是真实的,它会评估毒性,否则会使用新的物体。
a || b
OR营运人 > > >短路。 也就是说,如果<代码>a
是真实的,那么a > > > 是真实的。 该代码。 如果
a <>/code>不属实,则将其退回
b
,即在这种情况下,如果b<>>>> > /code>是伪造的,则该表述是假的,如果
b
是真实的。 http://www.ohchr.org。
这是:
var xin = (function (name) {return name;}(xin || {}));
这完全相同:
var xin = xin || {};
可以重申:
var xin = xin ? xin : {};
进一步加强我们:
if(!xin) xin = {}
如果没有任何新鲜毒素反对,它就会把新的(或现有的)新毒素带上新功能。
这是人为造名空间的comm。
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.