1

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()

1 Answers1

-2

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.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • If you're going to do that, you probably need to bind the function back to `obj`. –  Sep 04 '18 at 19:24