What I'm looking for is actually a shortcut for JS
obj.fn && obj.fn();
code. One of the reasons for that is sometimes the obj.fn
part might be quite long.
C# uses the Null Conditional Operators for that: obj?.fn()
What I'm looking for is actually a shortcut for JS
obj.fn && obj.fn();
code. One of the reasons for that is sometimes the obj.fn
part might be quite long.
C# uses the Null Conditional Operators for that: obj?.fn()
One of the reasons for that is sometimes the obj.fn part might be quite long.
var a = obj.fn;
a && a();
Now you only use the long part once. That's likely the closest you'll get in javascript.