Skip to content

Instantly share code, notes, and snippets.

@kevinpeno
Last active December 21, 2015 17:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinpeno/09d629275de36549cbb5 to your computer and use it in GitHub Desktop.
Save kevinpeno/09d629275de36549cbb5 to your computer and use it in GitHub Desktop.
/*
ES2015 fat arrow noop
*/
() => {}
/*
My fat arrow noop
*/
( => )
/*
ES2015 fat arrow noop set to variable
*/
// #1 no args, no wrap/body:
let foo = () => // syntax error
// #2 no args, wrap, no body:
let foo = (() => ) // syntax error
// #3 no args, no wrap, body:
let foo = () => {} // undefined -- foo === () => {}
// #4 no args, wrap, body:
let foo = (() => {}) // undefined -- foo === () => {}
// #5 no args, wrap, body w/ logic:
let foo = (() => {
if(true){
return true
}
}) // undefined -- foo === () => {}
/*
My fat arrows set to variable
Note: I don't think we'll need the body wrapper {},
but I included it for comparison
*/
// #1 no args, no wrap/body:
let foo = => // undefined -- foo === () => {}
// #2 no args, wrap, no body:
let foo = ( => ) // undefined -- foo === () => {}
// #3 no args, no wrap, body:
// I don't think this is necessary to support see #5
// However it is not harmful and follows language constructs -- accidental usage is not damaging
let foo = => {} // undefined -- foo === () => {}
// #4 no args, wrap, body:
// I don't think this is necessary to support see #5
// However it is not harmful and follows language constructs -- accidental usage is not damaging
let foo = ( => {}) // undefined -- foo === () => {}
// #5 no args, wrap, body w/ logic:
let foo = ( =>
if(true){
return true
}
) // undefined -- foo === () => {}
/*
ES2015 fat arrow noop as callback
foo only takes one argument
*/
let foo = (noop => noop())
// #1 no args, no wrap/body:
foo(() => ) // syntax error
// #2 no args, wrap, no body:
foo((() => )) // syntax error
// #3 no args, no wrap, body:
foo(() => {}) // undefined
// #4 no args, wrap, body:
foo((() => {})) // undefined
// #5 no args, body w/ logic:
foo(() => {
if(true){
return true
}
}) // true
/*
My fat arrow noop as callback
*/
let foo = noop => noop()
// #1 no args, no wrap/body:
foo( => ) // undefined
// #2 no args, wrap, no body:
foo(( => )) // undefined
// #3 no args, no wrap, body:
// I don't think this is necessary to support see #5
// However it is not harmful and follows language constructs -- accidental usage is not damaging
foo( => {}) // undefined
// #4 no args, wrap, body:
// However it is not harmful and follows language constructs -- accidental usage is not damaging
foo(( => {})) // undefined
// #5 no args, body w/ logic:
foo( =>
if(true){
return true
}
) // true
/*
Fat arrow in multiple arg function
This is where ambiguity starts to show
*/
// ES2015
// notice the change here because we use paren for args same as line 25 vs 28
let foo = (bar, noop) => [bar,noop()] // undefined
// because arrow func have args separated by comma we have to use paren for arg list
// function body is required
foo(true,(baz) => {}) // [true, undefined]
// Mine
let foo = bar, noop => [bar,noop()]
// because arrow func have args separated by comma we have to use paren
// but we still don't need func body wrapper or arg list wrapper
foo(true,(baz => )) // [true, undefined]
/*
Other examples of callbacks
*/
// ES2015 -- args must be surrounded with paren or syntax error
func((foo, bar, baz) => {})
// Mine -- order of precedence defines args; is the same as above
func(foo, bar, baz => )
// ES2015 example with function body
func((foo, bar, baz) => {
return true
})
// My version example with function body
func(foo, bar, baz =>
return true
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment