i got two javascript objects api and myApi :
var api = {};
api.foo = function(){ ... };
api.foo2 = function(){ ... };
var myApi = {};
myApi.foo = function(){ ...};
myApi.myFoo = function(){ ...};
myApi.myFoo2 = function(){ ...};
i want to add all myApi.* functions to api object without overriding api.foo.
Indeed, i want learn how to extend APIs to each other and developing plugins with javascript.
What are the best practices in this subject?
To answer the first part of your question, you can modify the
mergemethod I use in some of my code:To not overwrite preexisting objects, you would have to add a check: