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循環。
如果我沒能解釋這個正確,請讓我知道我會盡量做的更好:)