4 ms·
Sure thing, but could you show an example? Let's say we want the `rename` function be private, this is what I came up with: https://gist.github.com/ravicious/54
by ravicious 11y ago
Sure thing, but could you show an example? Let's say we want the `rename` function be private, this is what I came up with: https://gist.github.com/ravicious/5412eebf8a1934ec7886 https://gist.github.com/ravicious/5412eebf8a1934ec7886
I don't particularly like this solution, because now I can't just write `this.rename()` in other Person functions. That's why I'd rather have a baked-in way to define private properties & functions instead of having to use (in my opinion) this weird syntax and later explain the whys and hows to other developers.
- braythwayt 11y agoWriting this[rename](...) instead of this.rename(...) is hardly onerous. Your solution mostly works, but a simpler one takes advantage of combining computed property keys and compact method syntax: https://gist.github.com/raganwald/18f8c179101cfd93c291 https://gist.github.com/raganwald/18f8c179101cfd93c291
- ravicious 11y agoOkay, now this certainly feels better than my example and is much more bulletproof than prefixing function names with `_`, thanks.
- mikegerwitz 11y agoYou wouldn't be able to simply; the same issues exist as in ES3 in this regard. (I wrote about them extensively years back here: http://mikegerwitz.com/papers/coope/coope.pdf. http://mikegerwitz.com/papers/coope/coope.pdf.)