javascript - Unexpected beahviour when replacing object properties -


i'm using mocha run tests against newly written class , need build number of event's make comparison. i've planned use object stubs , replace them actual instances of event class, have async constructor due db connection usage. i'm using recursive calls process stubs in sequence. , here problem: stub objects replaced latest instance , have no idea why. please explain me wrong.

event.coffee:

class event     start = 0     duration = 0     title = ""     atype = {}      constructor: (_start, _duration, _title, _atype, cb) ->         start = _start         duration = _duration         title = _title          evt = @         activitytype.find( {} =             where: {} =                 title: _atype         ).success( (res) ->             atype = res              cb? evt         ).error( () ->             throw new error "unable assign atype '#{_atype}'"         ) # ... 

event.test.coffee:

# ... suite "geteventat", () ->     events =         free: {} =             start: 0             duration: day.minutes_per_day             title: "free time"             type: "free"         rest: {} =             start: 10             duration: 30             title: "rest"             type: "_rest"         fitness: {} =             start: 30             duration: 30             title: "fitness"             type: "_fitness"         work: {} =             start: 20             duration: 30             title: "work"             type: "_work"      suitesetup (done) ->         buildevent = (ki) ->             ks = object.keys events             ( (k) ->                 v = events[k]                 new event v.start, v.duration, v.title, v.type, (e) ->                     events[k] = e                     if k == ks[ks.length-1]                         return done?()                     return buildevent(ki+1)             )(ks[ki])         buildevent(0) # ... 

start duration title , atype class variables, overwritten each time create new event

class event      constructor: (_start, _duration, _title, _atype, cb) ->         @start = _start         @duration = _duration         @title = _title          evt = @         activitytype.find( {} =             where: {} =                 title: _atype         ).success( (res) =>             @atype = res              cb? evt         ).error( () ->             throw new error "unable assign atype '#{_atype}'"         ) 

please, note flat-arrow @ success callback (see: http://coffeescript.org/#fat-arrow further details)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -