In js... Deconstruction assignment of expression

go directly to the code

function Person (a, b) {
  this.a = a;
  this.b = b;
  
  this.get = (name) => {
      return this[name]
  }
}

let obj = {
  a: 1,
  b: 2,
  c: 3,
}
let obj2 = new Person(11, 22)
let url = new URL("https://jsfiddle.net")

console.log({...obj})
console.log("==================")
console.log(obj2)
console.log({...obj2})
console.log("==================")
console.log(url)
console.log({...url})

the result is:

clipboard.png

question:
Why is the result of console.log ({... url}) an empty object?

Jul.07,2022

https://developer.mozilla.org...
take a look at


. applies only to iterable objects. New URL () is not an iterable object

.
Menu