Q: Using an object as a prototype Can anyone tell me why this code does not work?
PhoneNumber.prototype = Map;

var Map = {
    writeToDOM : function(container) {
        //DO STUFF HERE
    }   
};

PhoneNumber.writeToDOM(Container);

Is it not possible to reference an object in respect to an object's protype and use said object's functions? The reason I would want to do this is so I can use the Map variable on multiple objects rather than having to repeat the writeToDOM code for each object like this:
Object1.prototype.writeToDOM = function() {
    //DO STUFF HERE
}

Object2.prototype.writeToDOM = function() {
    //DO the exact same stuff as Object1
}


A: Your code is equivalent to the following:
var Map;
PhoneNumber.prototype = Map;

Map = {
    writeToDOM : function(container) {
        //DO STUFF HERE
    }   
};

PhoneNumber.writeToDOM(Container);

That is, you are assigning PhoneNumber.prototype to Map, which currently contains undefined. Then you are reassigning Map to a new value, but not changing PhoneNumber.prototype at all.

If you simply assigned Map to the desired object before assigning the prototype to Map, you would be OK:
var Map = {
    writeToDOM : function(container) {
        //DO STUFF HERE
    }   
};

PhoneNumber.prototype = Map;

PhoneNumber.writeToDOM(Container);


A: Thanks to variable declaration hoisting, what is actually happening when your code runs is this:
var Map; // = undefined;

PhoneNumber.prototype = Map;

Map = {
   writeToDOM : function(container) {
     //DO STUFF HERE
   }
};

PhoneNumber.writeToDOM(Container);

Regardless of where you put your var statement(s) JS treats them as if they were at the top of that scope, but doesn't assign the values until the line where you did so. So at the point where you try to use Map it is still undefined.
Move your Map assignment up to before PhoneNumber.prototype = Map.

A: You could use something like this:
var Map = {
  writeToDOM: function() {
    // stuff
  }
}

var extend = function(obj, proto) {
  for(var k in proto) {
    obj.prototype[k] = proto[k];
  }
}

extend(Object1, Map);
extend(Object2, Map);


A: Try the following code:
function PhoneNumber (){}
PhoneNumber.prototype = Map;

var Map = {
   writeToDOM : function() {
     console.log("test");
   }   
};


var instance = new PhoneNumber();
instance.writeToDOM();


A: As per me it can be done without using prototype also.
var Map = {
    writeToDOM : function(container) {
       console.log("written to "+container); //container is string  
    }   
};
function PhoneNumber(name,no){
        var map=Map;
    this.name="user";
    this.no=100;
        return{
         toString:function(){
            return this.name+"-"+this.no;
           },
         writeToDOM:map.writeToDOM
         }
}
var phone1=new PhoneNumber("cham",100002);
console.log(phone1.writeToDOM("body"));


A: Modify to this:

var Map;
  PhoneNumber.prototype = Map;
Map = {
      writeToDOM : function(container) {
          //DO STUFF HERE
      }    };
PhoneNumber.writeToDOM(Container);

