What's the difference between writing 'Effect.Highlight(…)' and 'new Effect.Highlight(…)'?
-
21-12-2020 - |
Question
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.
Solution
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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow