I’ve seen many javascript objects that have a ‘init’ method that you pass in values to in order to setup the object.
How do they internally handle the initializations of their private variables when passed in a array of name/value pairs like:
myObject.init( {prop1: ‘blah’, prop2: ‘asdf’, …, propn: ‘n’} );
Specifically, some of these values can be optional, so how would you setup defaults and then override them if the name/value pair was passed in during the init.
1 Answer