MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/30hyan/airbnb_javascript_style_guide_a_mostly_reasonable/cpt2i4p/?context=3
r/javascript • u/mrkipling • Mar 27 '15
158 comments sorted by
View all comments
2
// bad Jedi.prototype = { fight: function fight() { console.log('fighting'); } }; // good Jedi.prototype.fight = function fight() { console.log('fighting'); };
wouldn't this be an even safer and more convenient way?
Object.defineProperties(Jedi.prototype, { fight: { value: function () { console.log('fighting'); }, enumerable: false } });
that way you can safely use for...in loops without hassle, prototypes are hidden and you can extend the prototype with multiple functions at once.
downside is that it's not for IE8...
2 u/qudat Mar 27 '15 To me you'd be sacrificing readability, caused by boomeranging. I tend to prefer the style of coding that flattens code. 1 u/BONUSBOX _=O=>_();_() Mar 27 '15 Object.defineProperty(Jedi.prototype, 'fight', { value: function () { console.log('fighting'); }, enumerable: false });my best offer 1 u/tomcam Mar 28 '15 Sold!
To me you'd be sacrificing readability, caused by boomeranging. I tend to prefer the style of coding that flattens code.
1 u/BONUSBOX _=O=>_();_() Mar 27 '15 Object.defineProperty(Jedi.prototype, 'fight', { value: function () { console.log('fighting'); }, enumerable: false });my best offer 1 u/tomcam Mar 28 '15 Sold!
1
Object.defineProperty(Jedi.prototype, 'fight', { value: function () { console.log('fighting'); }, enumerable: false });
my best offer
1 u/tomcam Mar 28 '15 Sold!
Sold!
2
u/BONUSBOX _=O=>_();_() Mar 27 '15
wouldn't this be an even safer and more convenient way?
that way you can safely use for...in loops without hassle, prototypes are hidden and you can extend the prototype with multiple functions at once.
downside is that it's not for IE8...