3 ms·
Ok. I'm not convinced at all, we'll simply have to agree to disagree on that. And I'd love to see the codebase of a JS app that completely bans the "function"
by orange8 7y ago
Ok.
I'm not convinced at all, we'll simply have to agree to disagree on that.
And I'd love to see the codebase of a JS app that completely bans the "function" keyword. Any links or examples?
- ratww 7y agoAnecdotal if you're interested: I can't show it since it belongs to the company, but I just ran a grep in the app I architected and it has exactly 21 instances of the word "function"... some are comments, but most of the ones that aren't are inside a lodash debounce function. Total of 140000 non-blank/non-commented lines of code. Btw, it's not banned, and I never really enforced it... but since I never use it myself, I guess the others devs picked it up? It's in Vue.js, and in Vue you rarely see old-style functions anywhere, so there's that.
- orange8 7y agoThat's interesting. However, the Vue.js library itself uses the "function" keyword a lot, and the library is part of your applications code. Infact, it uses normal functions almost exclusively. source: https://raw.githubusercontent.com/vuejs/vue/dev/dist/vue.common.dev.js https://raw.githubusercontent.com/vuejs/vue/dev/dist/vue.com... Furthermore, the official Vue documentation explicitly discourage the use of arrow functions in some places, so whoever set that rule just did not know what they were doing, sorry if that sounds harsh. source: - https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-Hooks https://vuejs.org/v2/guide/instance.html#Instance-Lifecycle-... - https://stackoverflow.com/questions/43929650/vuejs-why-is-this-undefined https://stackoverflow.com/questions/43929650/vuejs-why-is-th... Saying all arrows functions are bad and evil or that all normal functions are bad and evil is nothing but dogma. Each has its own place and uses, it seems many JS devs would rather not think of this at all and just use one form everywhere.
- ratww 7y agoWe're not using arrow functions for everything. Why are you assuming this? We're using shorthand syntax in methods inside Vue.js objects [1], they also don't need the "function" keyword. In fact, they are suggested in the second link you posted, please read again. Arrow functions wouldn't even work in this situation. We're mainly using two forms: shorthand and arrow. That's how we only have 21 instances of the "function" word in our entire JS codebase, and we could remove all of them if we wanted. That's what you asked for: a "JS app that completely bans the 'function' keyword". Well, we don't ban but it's possible. And please read my comment again: I explicitly mentioned that this is not a rule, and I never enforced it. The team (39 committers ATM) reached that result organically, mostly influenced by my own personal style. And sorry if this sounds harsh, but it seems that you have extremely limited knowledge of Javascript and ES6, so I'd suggest learning before you make such claims before you make a fool of yourself. Btw, you're seem to be the one holding on to dogma here, since you seem unable to accept that the keyword is not strictly necessary in a large app. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- orange8 7y agoshorthand object method syntax === regular function shorthand object method syntax != arrow function > We're not using arrow functions for everything. Why are you assuming this? Because you said "but I just ran a grep in the app I architected and it has exactly 21 instances of the word "function"... some are comments, but most of the ones that aren't are inside a lodash debounce function." Seriously, am I in some kind of twilight zone or something? Because that statement suggests that there was a goal, and the goal was to get rid of "function" but lodash debounce ruined the anti-function-keyword cult party. Who runs a grep on a whol;e web app to see if there are any "function" keywords, then shamelessly turns around to say "We're not using arrow functions for everything.". If you know you are not using arrow functions for everything, WHY GREP THE WHOLE CODEBASE LOOKING FOR "function"? And whats all that about "some are comments". Right? Phew! We did not really use it, they are just comments. We did not really use that old, evil 'function' keyword. It was just comments... we're too cool and hip for "function". LOL!!! > And sorry if this sounds harsh, but it seems that you have extremely limited knowledge of Javascript and ES6 Hilarious! Bwahahahahaaaaaaaaaaaa! Thank you sir for your information, all this time I thought I knew, but you've corrected me. Now I know I don't know. Thank you genius.
- ratww 7y agoFirst of all, are you aware of shorthand methods? Are you aware that you can have non-arrow functions without the "function" keyword :) ES6 has grown :) And there was no goal intended with the grep. This is what you wrote: > And I'd love to see the codebase of a JS app that completely bans the "function" keyword I just grepped "function" to give you a personal anecdote of an app that doesn't need to use the "function" keyword much. That was the first time I interacted with you, I was trying to be nice then, and you were completely hostile. Some of the replies were completely uncalled for. --- EDIT: You just edited your message to add the part about shorthand methods. My point still stands. I never claimed to be only using arrow functions (in fact, you're the one who DID claim I was only using arrow functions!). I only claimed we rarely use the "function" keyword.
- orange8 7y ago
- sergeykish 7y agoSorry, typo >> Yes, <typo>they</typo> replace<typo>d</typo> "function" usage with safe alternatives. And don't forget 'use strict' - it affected "function" too. > I'm not convinced at all It could appear I've tried to convince you not to use "function". That never was the case, should have added at least one. And I do not agree with TC39 direction, just making observations. Please check my comment assuming that and typo. My fix would be different. Prototype based inheritance is awesome http://iolanguage.com/tutorial.html http://iolanguage.com/tutorial.html and javascript could be as simple too: Object Object.__proto__ === null object = new Object object.__proto__ === Object object.constructor === Object.constructor object.toString === Object.toString f = new Function f.__proto__ === Function fun.constructor === Function object.private = function () { return 'hello' } Object.shared = function () { return 'world' } Object.constructor.static = function () { return '!' } // we need functions with just a simple change Object = Object.prototype Function = Function.prototype syntax new = function (ctx) { let ident = ctx.next().value return #`new ${ident}.constructor` } It looks almost boring (just don't redefine .constructor). Now this one is much harder: Object.prototype Object.prototype.__proto__ === null object = new Object object.__proto__ === Object.prototype object.constructor === Object object.toString === Object.prototype.toString fun = new Function fun.__proto__ === Function.prototype fun.constructor === Function object.private = function () { return 'hello' } Object.prototype.shared = function () { return 'world' } Object.static = function () { return '!' } // we need functions