Your property is enumerable, that's why it appears in both objects when you iterate.
A solution would be this :
Object.defineProperty Object.prototype, 'intersect', value:(obj)->
t = {}
t[k] = @[k] for k of obj
t
Demonstration (compiled as JS)
But modifying objects you don't own, especially Object
is terrible practice and can lead to many unexpected problems for other coders. Read Maintainable JavaScript: Don’t modify objects you don’t own.
Here it would be as easy and so much cleaner to simply define a function taking two objects as arguments...