Return to Snippet

Revision: 11871
at February 23, 2009 00:20 by Sephr


Initial Code
function namespace(fullNS, separator) void
  let(parent = this) fullNS.split(separator || '.').forEach(function(ns)
    parent = parent[ns] = parent[ns] || {}
  );

String.prototype.namespace = function(separator, thisp) void
  namespace.call((thisp||window), this, separator);

Initial URL

                                

Initial Description
Easy Namespacing
================
*Requires JavaScript 1.8*

Examples:

`"foo.bar.baz".namespace()` makes `foo.bar.baz`

`"foo::bar::baz".namespace("::")` makes `foo.bar.baz`

`namespace.call(obj, ns[, separator])` extends `ns` (split by separator or ".") onto `obj`

Initial Title
Easy Namespacing (JS 1.8)

Initial Tags

                                

Initial Language
JavaScript