In coffee script, using the existential operator on a function like so:
myFunc?()
compiles to
typeof myFunc === "function" ? myFunc() : void 0;
Is there a way to elegantly define what would go in place of “void 0”? or must I write it all out instead of using the original notation?
You can add another existential operator:
That won’t work if
f()returnsnullorundefinedbut it will do the Right Thing iff()returnsfalse. For example:Demo: http://jsfiddle.net/ambiguous/f6yvN/1/
So you can get close to what you want and that might be close enough depending on what sort of things you’re expecting the function to return.