I'd like to emulate ActiveRecord scopes on a CoffeeScript class.
What's tripping me up is the context when defining the @scope function. The @scope function itself should execute in the context of the underlying class, but the function it is passed should operate in the context of that instance.
Here is what I have, but the popped function ends up running in the context of Window instead of the instance that called it.
class Collection
models: []
@scope: (name, funct) ->
@.prototype[name] = ->
new @constructor(funct())
constructor: (models) ->
@models = models
class Bubbles extends Collection
@scope 'popped', ->
@models.slice(1, @models.length)
first: ->
@models[0]
console.log(new Bubbles([1,2,3,4]).popped()) # should return an instance of Bubbles with models == [2,3,4]