The problem is that you are returning a property called prototype with the value parent, which is the object, so you are returning a pair of prototype = {name = 'keith'} , and when you call a new obj object, you add a new property to prototype a with named prototype .
You just need to change a little, I need this is what you are trying to do. This will work, just be careful with overload properties.
var obj = function(parent){ for(var propt in parent){ this[propt] = parent[propt]; } } var me = { name: 'keith' }; var a = new obj(me); console.log(a);
Edit: if you are looking for prototype inheritance, you should read this or try TypeScript , the new javascript introduced and the OO library
source share