javascript - Augment properties with literal notation -


let's assume have following coffeescript code:

person =   name: 'alice' 

now, want augment object 2 additional properties. common way write:

person.age = 34 person.bestfriend = 'bob' 

however, don't repeating person. however, writing:

person =   age: 34   bestfriend: 'bob' 

(unfortunately) creates whole new object , assigns person variable, meaning alice has lost name. there nicer way augment object in coffeescript besides writing property assignments line line? like:

person.augment   age: 34   bestfriend: 'bob'   

not language feature, writing simple extend function easy enough (or use existing version on underscore or jquery):

extend = (dst, src) ->   dst[k] = src[k] k of src   dst  person =   name: 'alice'  extend person,   age: 34   bestfriend: 'bob' 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -