title: how can i create an objects property from variables in javascript?
body: <p>i want to do something like this,</p>
  
  <pre><code>function MyObject(args){
      keys=Object.getOwnPropertyNames(args)
      keys.forEach(function(key){
          this[key]=args[key]             
      })
  }
  </code></pre>
  
  <p>after this i tried creating an object, but it's attributes were not set..</p>
  
  <pre><code>n=new MyObject({title:'x',age:19})
  console.log(n.title)
  </code></pre>
  
  <p>OutPut:undefined!!</p>
  
  <p>so can anyone tell me what im doing wrong...i even tried replaced <code>this[key]</code> with <code>MyObject[key]</code>, but got same result..</p>