English 中文(简体)
Javascript !instanceof 声明
原标题:Javascript !instanceof If Statement

这是一个真正的基本问题,真的只是满足我的好奇,但也有办法这样做:

if(obj !instanceof Array) {
    //The object is not an instance of Array
} else {
    //The object is an instance of Array
}

这里的关键是能够在前方使用NOT! 通常,我必须这样做的方式就是:

if(obj instanceof Array) {
    //Do nothing here
} else {
    //The object is not an instance of Array
    //Perform actions!
}

在我只想知道该物体是否属于特定类别时,我几乎不想再作陈述。

最佳回答

parent在母体内,在外部 ne。

if(!(obj instanceof Array)) {
    //...
}

In this case, the order of precedence is important. See: Operator Precedence.

<!营运人,先见instanceof营运人。

问题回答
if (!(obj instanceof Array)) {
    // do something
}

这样做的正确方式——正如其他人已经回答的那样。 所建议的其他两种战术不会奏效,应当理解......

在<代码>的情况下,“的操作人,无方括号。

if (!obj instanceof Array) {
    // do something
}

在此情况下,优先秩序是重要的()。 <!营运人,先见instanceof营运人。 因此,!obj 评价为false 首先(相当于! Boolean(obj);然后,你正在测试Array>false instanceof Array

In the case of the ! operator before the instanceof operator.

if (obj !instanceof Array) {
    // do something
}

这是一种yn错。 诸如<代码>!=等操作员是单一操作员,而NOT则适用于平等生活标准。 没有这样的操作者,例如<代码>!instanceof,其方式与没有!<的操作者相同。





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

热门标签