0
我有以下的CoffeeScript类具有隐藏属性扩展对象
class Data
constructor: (data)->
data.prototype.meta = @meta
return data
meta: ->
return { id: 123 }
# this is how I want to work with it, as an example
a = {name: "val"}
x = new Data a
for key, item of x
console.log key, item ## should say `name`, `val` (not meta)
console.log x.meta ## should say `{id:123}
我想给meta
属性添加到现有的object
,但我不希望meta
上来时,我环路在新对象x
上使用for循环。
如果我没能解释这个正确,请让我知道我会尽量做的更好:)