I can not understand how to overwrite the value of an object on js with the help of for in ?
var Test = (function () { "use strict"; var def = { test: '1', test2: '2' }; function _run(data) { for (def in data) { /* ???? */ } //результат console.log(def.test) // >> hi } return { run: function (data) { _run(data); } } }()); Test.run({ test: 'hi', test2: 'hi2' }); Test.run(); - values remain default (def.test = 1, def.test2 = 2)
Test.run({test: 'hi'}); - overwrite only test, leave test2 as default. Test.tun({olala: 'hi'}); - give the error "no such parameter".
defobject? and if in the transferred object there are fields which are not in object def? - Grundy{test:'hi'}and{test:'hi', test2:'hi', test3:'hi'},{test:'hi', test3:'hi'}? - Grundy