Question: I have the following code:

```
this.myObject = {
   key1: "val1",
   key2: "val2"
}

this.aMethod = function (newObject) {
    ...

```

Here I want a new object (probably that inherits from `this.myObject`) that contains everything in `this.myObject` *plus* whatever is in `newObject` also, fields in `newObject` should override already existing fields in `this.myObject`

How do I do this?

This idea is that `this.myObject` provides some default values - but the user of the method can override these values. I'm open to criticisms of this overall "pattern" as well. Thanks.

Answer: 
Thus spoke Douglas Crockford:

```
function object (o) {
  function F() {}
  F.prototype = o;
  return new F();
}

```

There are literally dozens of ways to do that. The videos at [Yahoo Theater](http://developer.yahoo.com/yui/usg=AFQjCNGcNmscGXZsXmSic0iRDCFgs8wWsg&sig2=jDcZ29V7HHHy9PFJfgNWxA), and the books [Javascript: The Good Parts](https://rads.stackoverflow.com/amzn/click/com/B0026OR2ZY) and [Object Oriented Javascript](https://rads.stackoverflow.com/amzn/click/com/1847194141) explore some trade-offs. Many javascript libraries implement a simple "class-like" inheritance pattern, but it's just a small piece of the whole cake.
this should do the work:

```
this.aMethod = function(newObject){
  combinedObject = {};
  for(key in this.myObject){
    combinedObject[key] = this.myObject[key];
  }
  for(key in newObject){
    combinedObject[key] = newObject[key];
  }
  return combinedObject;
}

```

or, if you are using jquery, in one line:

```
return $.extend({},this.myObject,newObject);

```