JavaScript Arguments at instantiation of a namespace

I have a namespace generator that looks like this: (As a requirement, it also needs to have prototype objects extra and default).

function generateNamespace(staticMethods, prototypeMethods){

     var namespace = function(){};  //create namespace
      /**add staticMehods and prototypeMethods to namespace*/
     extend(namespace, staticMethods); //extend function from NojeJS
     extend(namespace.prototype, prototypeMethods);

     //create extra and default objects. 
     namespace.prototype.default = namespace.prototype.default || {};
     namespace.prototype.extra = namespace.prototype.extra || {};

     return namespace;
}

The idea is to generate a namespace like this:

var protObj = {id: function(){
                     console.log("id");                
                   }
              }
var myNameSpace = generateNamespace({}, protObj);

When I instantiate:

var instanceOfmyNameSpace = new myNameSpace();

the result contains the functions id, and the objects default, and extra.

But if I run:

var instance2 = new myNameSpace({test: "foo"});

Then: assert.equal(instance2, instanceOfmyNameSpace) \\=true

so that means(?) that the given object just gets ignored.

What do I have to do to merge that object with the default one, for example? The perfect input/output would be:

//input
var instance2 = new myNameSpace({test: "foo"});
//output
console.log(instance2.default.test) \\->  "foo"

UPDATE, ANSWER

All I needed to do was create the namespace as a constructor, and then add staticMethods and prototypeMethods to it:

  var extend = require('util')._extend;
   function generateNamespace(staticMethods, prototypeMethods){
      var  namespace = function(defaults, extras){
           this.default = extend({}, this.constructor.default, defaults);
           this.extra = extend({}, this.constructor.extra, extras);
      }
      extend(namespace, staticMethods); 
      extend(namespace.prototype, prototypeMethods);

      return namespace;
   }
Answer:1

I am new to angularJS and am trying to use it to get data from a json file. When I run the program the console reads out there is a 404 error and that the file does not exist. Here is the angular i ...

I am new to angularJS and am trying to use it to get data from a json file. When I run the program the console reads out there is a 404 error and that the file does not exist. Here is the angular i ...

I have a site here. Here's the code from my little form... <form method="get" action="https://www.google.com/search" target="_blank"> <table border="0" cellpadding="0"> <...

I have a site here. Here's the code from my little form... <form method="get" action="https://www.google.com/search" target="_blank"> <table border="0" cellpadding="0"> <...

  1. display text text
  2. display text from text file in html
  3. display text in text box html
  4. display text on mouseover for text in html
  5. tkinter display text in text box
  6. excel if text display text

I want clocks displaying different time zones on a webpage that i am designing.For this,i have embedded the javascript files from a webiste called qlock.The HTML code is as follows: <script type="...

I want clocks displaying different time zones on a webpage that i am designing.For this,i have embedded the javascript files from a webiste called qlock.The HTML code is as follows: <script type="...

  1. css align blocks horizontally
  2. align div blocks horizontally

Looking at these articles from Mozilla's JavaScript guide: Expressions Statements expressions are also considered assignment statements. In fact, in the second article one can read "any expression ...

Looking at these articles from Mozilla's JavaScript guide: Expressions Statements expressions are also considered assignment statements. In fact, in the second article one can read "any expression ...