Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e71aad

Browse files
committed
Merge pull request jashkenas#1573 from geraldalewis/1464_bound_static_methods
1464 bound static methods
2 parents a03f2fe + 0e0d625 commit 4e71aad

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/nodes.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ exports.Class = class Class extends Base
858858
else
859859
unless assign.variable.this
860860
assign.variable = new Value(new Literal(name), [new Access(base, 'proto')])
861-
if func instanceof Code and func.bound
861+
if func instanceof Code and func.bound and not assign.variable.this
862862
@boundFuncs.push base
863863
func.bound = no
864864
assign

test/classes.coffee

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,13 @@ test "#1380: `super` with reserved names", ->
490490
class B
491491
0: -> super
492492
ok B::[0]
493+
494+
test "#1464: bound class methods should keep context", ->
495+
nonce = {}
496+
nonce2 = {}
497+
class C
498+
constructor: (@id) ->
499+
@boundStaticColon: => new this(nonce)
500+
@boundStaticEqual= => new this(nonce2)
501+
eq nonce, C.boundStaticColon().id
502+
eq nonce2, C.boundStaticEqual().id

0 commit comments

Comments
 (0)