es6/7 shorthand for assigning properties from object to HTMLElement

123 Views Asked by At

What would be a shorthand for the following:

setupIframeConfig(element: HTMLIFrameElement, config: IFrameConfig){
    element.src = config.src;
    element.width = config.width;
    element.width = config.width;
}

using rest wont do it because it will create a new object instead of the HTML element reference.

element = {...element, ...config}

thought maybe destructured assignmnent, but is used for declaring variables.

whats a shorthand es6/7 for this case?

1

There are 1 best solutions below

0
spender On BEST ANSWER

I'm assuming that you are looking for the least-verbose way of doing this.

Most likely this would be achieved by using Object.assign:

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object.

in your case, the target object is element and the only source object here would be config:

Object.assign(element, config)