Find file
Fetching contributors…
Cannot retrieve contributors at this time
15 lines (14 sloc) 718 Bytes
# Public Domain (-) 2011 The Jsutil Authors.
# See the Jsutil UNLICENSE file for details.
# The `define` function provides a utility wrapper to namespace code blocks. If
# an explicit target isn't passed in, it defaults to using `window` or `exports`
# as the top-level object.
#
# This functionality has been adapted from the `namespace` function defined in
# the [CoffeeScript FAQ](https://github.com/jashkenas/coffee-script/wiki/FAQ).
define = (root, name, constructor) ->
[root, name, constructor] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
target = root
target = target[item] or= {} for item in name.split '.'
constructor target, root
return