簡體   English   中英

如何返回與本地變量具有相同屬性名稱和值的對象

[英]How to return an object which same property name and value as a local variable

有人知道我將如何返回值xywh嗎? 下面的代碼不起作用,但是是我要實現的示例

 const selectorRect = (function() { let x = undefined; let y = undefined; let w = undefined; let h = undefined; return { x: x, y: y, w: w, h: h }; })(); console.log(selectorRect); 

ES6允許您使用速記屬性值。

const selectorRect = () => {
  let x = undefined;
  let y = undefined;
  let w = undefined;
  let h = undefined;
  return { x, y, w, h }
}

console.log(selectorRect())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM