English 中文(简体)
目 录
原标题:Purpose of var a = b.c = function(){} syntax

late code

var foo = bar.bi = function() {...}

这对我来说是不陌生的。 是否只是为同一职能界定两个名字? 如果是,为什么不仅将其定义为bar.bi =功能(?

最佳回答

同时也向变数和<代码>bi的>财产分配<条码>/条码>。

这样一来,物体的财产就有了价值,但你仍然可以把它看作是一个变数,可能更快。

......

bar.bi = function() {...};
var foo = bar.bi;

foo === bar.bi; // true

或你可以视之为......

var foo = ( bar.bi = function() {...} );

因此,对<代码>bar.bi的转让首先发生。 从转让表述中回收的结果是相同的功能,结果被分配到<代码>foo。

问题回答

除了将职能分配到2个变数之外,根据您的称呼,情况也发生了变化。

bar.bi();

(a) 符合《公约》第22条(a)项(b)项(b)项(b)项(c)项(c)项(c)项(c)目)

foo.call(bar);

但是,使用它与其他变量一样:

foo();

将使用<代码>foo。 因此,如果<条码>foo 在全球范围内,它就等于:

bar.bi.call(window);

It s just a compound assignment

var r = x = 3;

分配到3至x,并分配到一起,新申报。

Your example just substitutes a function in place of 3, and an object property—bar.bi—in place of x.

它取决于其使用地点。

<代码>fooandbar。bi 在此指同功能。 也就是说,可以利用这一职能来行使这一职能。

foo();

and

bar。bi();

同时,该功能中this的价值有所不同。 为使第1人与第2人平等,应援引如下规定:

foo。call(bar);  

foo。apply(bar);

这确保了<代码>该将注明该功能内的<条码>。

please refer:

https://developer。mozilla。org/en/Java/Reference/Global_Objects/Function/quest

var foo = bar.bi = function() {...};



bar.bi === function() {...} //true

foo === bar.bi //true

酒吧是响应方法二的物体。





相关问题
selected text in iframe

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.

How to fire event handlers on the link using javascript

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 ...

How to Add script codes before the </body> tag ASP.NET

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 ...

Clipboard access using Javascript - sans Flash?

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 ...

javascript debugging question

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 ...

Parsing date like twitter

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.

热门标签