What's the difference between writing 'Effect.Highlight(…)' and 'new Effect.Highlight(…)'?

StackOverflow https://stackoverflow.com/questions/7037928

  •  21-12-2020
  •  | 
  •  

質問

Both Effect.Highlight(...) and new Effect.Highlight(...) work just fine. So whats the difference in both usages, if any.

I started wondering about this because resharper (6) is showing me a warning when I use new Effect.Highlight(...): Expression statement is not assignment or call.

Manu.

役に立ちましたか?

解決

Looks like the Highlight() function is static, so you can call it either way, but the simplest one will always work:

Effect.Highlight(...)

Whereas instantiating a new object might not (if the class isn't supposed to be instantiated)

However, Javascript is generally soft on those kinds of function calls, so I'm guessing you could also use:

(new Effect).Highlight(...)

as long as you enclose the instantiation in parenthesis so the interpreter will know what you're trying to do

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top