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 8933325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:30:37+00:00 2026-06-15T09:30:37+00:00

I have a straightforward extend method set up like this: extend: function(source) { for

  • 0

I have a straightforward “extend” method set up like this:

extend: function(source) {
    for (var k in source) {
        if (source.hasOwnProperty(k)) {
            myThing[k] = source[k];
        }
    }
    return myThing;
}

You use it like

myThing.extend({ 
    newObj: { 
        myFunc: function () { console.log('things'); }
    }
});

and it works great.
However, I would love to add the ability to have some other piece of code call this LATER:

myThing.extend({ 
        newObj: { 
            mySecondFunc: function () { console.log('things'); }
        }
    });

and I should be able to call both myThing.newObj.myFunc() AND myThing.newObj.mySecondFunc().

I tried changing it to this:

for (var k in source) {
            if (source.hasOwnProperty(k)) {
                if (mtUtils.hasOwnProperty(k)) {
                    for (var t in k) {
                        mtUtils[k][t] = source[k][t];
                    }
                } else {
                    mtUtils[k] = source[k];
                }
            }
        }

but that doesn’t seem to work.

  • 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-06-15T09:30:38+00:00Added an answer on June 15, 2026 at 9:30 am

    This should fix your problem, but why not implement a recursive version of extend?

        for (var k in source) {
            if (source.hasOwnProperty(k)) {
                if (mtUtils.hasOwnProperty(k)) {
                    for (var t in source[k]) {
                        mtUtils[k][t] = source[k][t];
                    }
                } else {
                    mtUtils[k] = source[k];
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

IS this straightforward? Does any one have any good examples? All my google searches
This should be a pretty straightforward question. I have the following code, which forms
This should be pretty straightforward I would think. I have this string: [quote=Joe Johnson|1]Hi![/quote]
I'm trying to extend a LinearLayout to use as a composite component. I have
Below I have a simple method for painting a set of objects onto an
This seems like it should be pretty straightforward, but for some reason I am
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have a fairly straightforward WCF service that performs one-way file synchronization for a
I have implemented a straightforward OpenID support for my ASP.NET app with DotNetOpenAuth .
Hi I have a query which is very straightforward to write in mysql but

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.