mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-24 08:08:15 -05:00
31 lines
No EOL
1,003 B
CoffeeScript
31 lines
No EOL
1,003 B
CoffeeScript
module.exports.clone = (obj) ->
|
|
return obj if obj is null or typeof (obj) isnt "object"
|
|
temp = obj.constructor()
|
|
for key of obj
|
|
temp[key] = module.exports.clone(obj[key])
|
|
temp
|
|
|
|
module.exports.combineAncestralObject = (obj, propertyName) ->
|
|
combined = {}
|
|
while obj?[propertyName]
|
|
for key, value of obj[propertyName]
|
|
continue if combined[key]
|
|
combined[key] = value
|
|
if obj.__proto__
|
|
obj = obj.__proto__
|
|
else
|
|
# IE has no __proto__. TODO: does this even work? At most it doesn't crash.
|
|
obj = Object.getPrototypeOf(obj)
|
|
combined
|
|
|
|
module.exports.normalizeFunc = (func_thing, object) ->
|
|
# func could be a string to a function in this class
|
|
# or a function in its own right
|
|
object ?= {}
|
|
if _.isString(func_thing)
|
|
func = object[func_thing]
|
|
if not func
|
|
console.error("Could not find method", func_thing, 'in object', @)
|
|
return => null # always return a func, or Mediator will go boom
|
|
func_thing = func
|
|
return func_thing |