Last active
April 15, 2016 02:24
-
-
Save lukebarton/44e4ee303e45c264bdb9b9acd73b3ef6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
/** | |
* I'm using node 5.10.1 --harmony_default_parameters reporting v8 '4.6.85.31' | |
* | |
* [Bug] Default Parameters referring to class names do not work with Fat Arrow functions | |
* So I figured, maybe it's just a difference between Fat Arrow Functions and Full Functions, | |
* but then I realised that by declaring a Full Function referencing the class, | |
* it caused the Fat Arrow Function to execute fine. This tells me it's a bonafide bug. | |
*/ | |
/** | |
* This works as expected | |
*/ | |
const thisWorks = () => { | |
class myClass {} | |
const myFunc = function (a = new myClass) {} | |
myFunc() | |
} | |
/** | |
* This causes 'ReferenceError: myClass is not defined' | |
*/ | |
const thisProducesRuntimeError = () => { | |
class myClass {} | |
const myFunc = (a = new myClass) => {} /* Fat Arrow causes issue */ | |
myFunc() /* ReferenceError: myClass is not defined */ | |
} | |
/** | |
* But: This works | |
* It's functionally identical to thisProducesRuntimeError | |
* except it also declares a Full Function which is never invoked | |
* yet it avoids the ReferenceError issue on the Fat Arrow Function | |
*/ | |
const thisOddlyWorksToo = () => { | |
class myClass {} | |
const myFunc = (a = new myClass) => {} /* Fat Arrow is *expected* to cause issue */ | |
const neverCalled = function (a = new myClass) {} /* but this line somehow avoids issue with Fat Arrow */ | |
myFunc() | |
} | |
thisWorks() /* undefined */ | |
thisOddlyWorksToo() /* undefined */ | |
thisProducesRuntimeError() /* ReferenceError: myClass is not defined */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment