arrays - Set object property javascript -
i not sure possible guys can it:
var tricky = function(obj){ var ret = new object(); ret.porp1 = 'undefined'; ret.prop2 = 'undefined'; (porp in ret){ if (obj.hasownproperty(prop) == false){ obj.???????? = prop; } return obj; } tricky({prop1:'ok_prop'}); ===>>{prop1:'ok_prop',prop2:'undefined'}
i did not put question in words because find hard define properly. problem can see: have object , set properties in object not. want function check if object has range of properties , if not set explicitly undefined. not work if leave implicitly undefined, since use send jade template might have property set value system has changed state , want undefined.
what should put after obj.[what put here]
set @ first porp1 prop2.
i assuming want add members of "template" object ret
obj
if not exist & porp
typo.
you if not exist want set explicitly undefined there no need non-existent member of object undefined:
var x = new object(); alert (typeof x.wibble === 'undefined') //true
your ret.porp1 = 'undefined';
assigning string object textual content 'undefined'
member, has nothing state of being "undefined", if intention:
var tricky = function(obj) { var ret = { prop1: 'undefined', prop2: 'undefined' } (requiredmember in ret) { if (obj.hasownproperty(requiredmember) === false) { obj[requiredmember] = ret[requiredmember]; } } return obj; } var o = {prop1:'ok_prop'}; o = tricky(o); console.dir(o); object prop1: "ok_prop" prop2: "undefined"
Comments
Post a Comment