4 ms·
> If a colleague writes a function/method that returns something, in JS, how do I know what it is? Typically you have a set of standards for how things get ret
by BinaryIdiot 10y ago
> If a colleague writes a function/method that returns something, in JS, how do I know what it is?
Typically you have a set of standards for how things get returned. 'isSomething()' returns boolean, 'getSomething()' returns an object, 'getSomethingClassName()' gets a model representing that, etc.
Overall it's really the same as static: you usually have something in the function definition that makes it intuitive what it returns. The fallback is documentation directly above the function's implementation that should describe it.
When you run into the "well what does the object contain that gets returned?" situation then dynamic and static have the same issue: you have to go to the definition to get that information.
- Roboprog 10y agoFree your mind. Drop all that getXXX setXXX Java-esque noise. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... http://es6-features.org/#Proxying http://es6-features.org/#Proxying Otherwise, yeah, I can hardly make heads or tails of most "self documenting" (i.e. - undocumented, per SOP) static typed code.
- BinaryIdiot 10y ago> Free your mind. Drop all that getXXX setXXX Java-esque noise[...] You confuse my statement. I was not referring to things that should be meant as synchronous properties. These are methods that do more like make an AJAX call to a server. Those that return promises or take in callbacks would be awkward or impossible to force into a property or proxy. I was merely referring to the act of making code as obvious as possible for its intended outcome.
- Roboprog 10y agoGotcha. Sorry about the tangent, as you were primarily discussing grokking what the names of things were doing anyway.