javascript - What is the point of object assigning to an empty object? -


i'm asking because saw here:

https://github.com/bengrunfeld/react-flux-simple-app/blob/master/src/js/stores/appstore.js

var appstore = assign({}, eventemitter.prototype, {     emitchange: function() {         this.emit(change_event);     } }); 

i understand why assign eventemitter prototype, want of functionality of eventemitter; , last object assign override emitchange event. why first parameter empty object ({})? necessary? i've seen done couple times.

this due syntax of assign method takes first parameter object want put methods second object. can use existing object if don't have 1 pass new empty object {} assign copy methods , properties there , return modified.

have @ this: https://developer.mozilla.org/en/docs/web/javascript/reference/global_objects/object/assign


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -