I'm not really sure about the downcast concept, but for that I think I would use Object.assign(), using the enumerable property:
"use strict"
let person1 = { name: 'Doe', age: 25 }
let person2 = { name: '' }
for (let key in person1) {
if (!person2.hasOwnProperty(key)) {
Object.defineProperty(person1, key, { enumerable: false })
}
}
let person = Object.assign(person2, person1)
console.log(person) // { name: 'Doe' }
There is necessarily many ways to do this, as suggested in the other answers, and you can certainly make it a prototype if you need it that way.
edit:
I realize my first attempt was not very good at all as it change initial objects.
I take advantage of this to make it more simple:
let Person = function() {}
Person.prototype.downcast = function (p1, p2) {
let c = {}
for (let k in p1) {
if (p2.hasOwnProperty(k)) {
c[k] = p1[k]
}
}
return c
}
let person = new Person().downcast(person1, person2)
console.log(person) // { name: 'Doe' }