Why are javascript functions within classes not hoisted?
问题 class A { f1() { f2(); } f2() {} } var a = new A(); console.log(a.f1()); returns f2 is not defined. Whereas: { function f1() { return f2(); } function f2() { return 'f2'; } console.log(f1()); } prints 'f2' I'm just wondering why functions within classes are not hoisted? 回答1: class A { f1() { return f2() } f2() { return 'f2' } } var a = new A() console.log(a.f1()) is not equivalent to { function f1() { return f2() } function f2() { return 'f2' } console.log(f1()) } Instead, it is syntactic