Sha256: 9a2fc525f21c42330c3d732dbbe356953cbe27bb00bcb02bde47b94b1993e6e2

Contents?: true

Size: 939 Bytes

Versions: 11

Compression:

Stored size: 939 Bytes

Contents

prototypes = {}
@extendClass = (namespacedClass, methods)->
  declaredMethods = prototypes[namespacedClass] or= []
  declaredMethods.push methods
  modules = namespacedClass.split '.'
  className = modules.pop()
  module = extractModuleFrom modules
  module[className] or= class DynamicClass
    extend: extend
    constructor: ->
      @_className = namespacedClass
      extendClass this, declaredMethods.shift() while declaredMethods.length
      @initialize?.apply(this, arguments) # stack-overflow in IE8 if constructor is used instead of initialize

  extendClass = (_this, methods)->
    methods = methods.call(_this, _this) if methods instanceof Function
    extend DynamicClass.prototype, methods

extractModuleFrom = (modules, current = this)->
  return current unless modules.length
  current = current[modules.shift()] or= {}
  extractModuleFrom modules, current

extend = (target, obj)-> target[k] = v for k, v of obj; target

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
oojs-0.3.0 vendor/assets/javascripts/modules.js.coffee
oojs-0.2.3 vendor/assets/javascripts/modules.js.coffee
oojs-0.2.2 vendor/assets/javascripts/modules.js.coffee
oojs-0.2.1 vendor/assets/javascripts/modules.js.coffee
oojs-0.2.0 vendor/assets/javascripts/modules.js.coffee
oojs-0.1.1 vendor/assets/javascripts/modules.js.coffee
oojs-0.1.0 vendor/assets/javascripts/modules.js.coffee
oojs-0.0.4 vendor/assets/javascripts/modules.js.coffee
oojs-0.0.3 vendor/assets/javascripts/modules.js.coffee
oojs-0.0.2 vendor/assets/javascripts/modules.js.coffee
oojs-0.0.1 vendor/assets/javascripts/modules.js.coffee