3 ms·
What is 'build = (): string => {' ? Or specifically ():, I know arrow functions.
by Already__Taken 10y ago
What is 'build = (): string => {' ?
Or specifically ():, I know arrow functions.
- igl 10y ago() = empty arguments. you can only omit the braces when you have 1 argument. 0 and 2+ require the braces. #tc39 the colon refers to flow and typescripts type annotation "colon something". none-objects are lowercased
- deleted 10y ago[deleted]
- scottmf 10y agoLooks like build is the function and it returns a string. I think without the typing it would just be build = () => {
- Already__Taken 10y agovar build = function(){...} //return a string Rather than some other commenters, and I would have thought given arrow functions; var build = function(string){...}
- scottmf 10y agoI don't understand what you're trying to say?
- mcbits 10y agoIt's similar to writing build(): string { ... but they generate different JavaScript. The way it's written will give each instance its own reference to the function. The "build(): string" above will add the function to the prototype, which is shared by all instances. I'm not sure whether the code takes advantage of this difference in some way or not. If not, it's just a slightly more awkward and less efficient way of defining a method.
- ClayFerguson 10y agoThat strange syntax with the arrow function is only needed so that the 'this' inside the function behaves the way one would expect it to in normal OOP language. It 'captures' the this for the object itself (like C++ would, etc). But that 'build()' function is what constructs a string that is the content for the dialog.