javascript - Correct way to refer to class/instance rather than object literal property? -


i have object 'foo', object literal property, shown below. inside property, i'd refer object 'foo' rather object literal itself.

can done hacks, ie, referring object variable name? or there better way?

example below - should print 'woo' on success.

class foo   myfunc: =>     console.log('woo')   testthing: {     'foo':'bar'     'baz':'boo'     'bop': =>       @myfunc()   }  window.foo = new foo  foo.testthing.bop() 

class foo   constructor: ->     @testthing =       'foo':'bar'       'baz':'boo'       'bop': => @myfunc()   myfunc: =>     console.log('woo') 

declaring testthing in constructor allows @myfunc bound 'instance' rather 'class'.

you use 'bop': @myfunc instead of 'bop': => @myfunc() pass along arguments :)


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -