Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3284302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:08:22+00:00 2026-05-17T20:08:22+00:00

i got two javascript objects api and myApi : var api = {}; api.foo

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T20:08:23+00:00Added an answer on May 17, 2026 at 8:08 pm

    To answer the first part of your question, you can modify the merge method I use in some of my code:

    if (typeof Object.merge !== 'function') {
        Object.merge = function (o1, o2) { // Function to merge all of the properties from one object into another
            for(var i in o2) { o1[i] = o2[i]; }
            return o1;
        };
    } 
    

    To not overwrite preexisting objects, you would have to add a check:

    if (typeof Object.merge !== 'function') {
        Object.merge = function (o1, o2) { // Function to merge all of the properties from one object into another
            for(var i in o2) { if(!(i in o1)) o1[i] = o2[i]; }
            return o1;
        };
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two SVN branches (eg development and stable) and want to switch from
We've got two developers on the same closed (ugh, stupid gov) network, Another developer
I've got two models: Message and Attachment. Each attachment is attached to a specific
I've got two Silverlight Controls in my project, both have properties TeamId. I would
I've got two controls in my Interface Builder file, and each of those controls
I've got two tables in my database: Articles and Tags The Tags tables consist
I've got two tables: TableA ------ ID, Name TableB ------ ID, SomeColumn, TableA_ID (FK
I've got two arrays of the same size. I'd like to merge the two
Say I've got two scheduled processes: A and B. Given that B should not
I've got two directories containing ~20 GB of music files (mostly mp3, some ogg),

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.