English 中文(简体)
Java Ternary Businesstor and JSLint
原标题:Expressions in JavaScript Ternary Operator and JSLint

最近,我收到了关于我的一个博客职位对《联合起来倡议》的评论,询问为什么《联合起来法》在以下几个方面留下了一个错误:

s === "test" ? MyFunc() : MyFunc2();

The error generated was:

"Expected an assignment or function call and instead saw an expression."

很显然,联合后勤组织期待在此进行一项任务,更像:

var y = (s === "test") ? MyFunc() : MyFunc2();

但是,我并没有真正以第一个例子看待这一问题。 究竟是应当只利用私人经营人进行转让?

参看JSLint.com上的任何内容,《Java: The Good Parts》一书中也没有任何明显的内容。 此外,社区也报告了同样的错误:JSHint

谁?

最佳回答

它是一种表述。 相当于书写

<0> = = 1;

你再写一个具有直接副作用、被认为坏的表述。

一般说来的是无用的表述,没有副作用。 仅仅这样做被认为是更好的形式

if (s === "test") {
  MyFunc();
} else {
  MyFunc2();
}

除此以外,它还非常稳固。 我个人确实同意,如果<>条码/代码>是坏的,则作为<条码>的一种替代物书写一种手法,而且你只有在进行转让时才加以改换。

用于(b) ter的其他短手表述

someCondition && doMagic(magic);
someCondition || doMagic(magic);

如果仅仅使用这些简单模糊的逻辑,使守则更加难以维持,那么这种说法就被视为不正确。

JSHint有这方面的选择expr。 见https://github.com/jshint/jshint/issues/23”rel=“noreferer”>ticket

履历:

/*jshint
  expr: true
*/

var s, MyFunc, MyFunc2;
s === "test" ? MyFunc() : MyFunc2();
0 === 1;

通行证

问题回答

暂无回答




相关问题
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.

热门标签