diff --git a/lib/dust.js b/lib/dust.js index 7a664b43..bb59338c 100644 --- a/lib/dust.js +++ b/lib/dust.js @@ -328,12 +328,17 @@ this.options = options; this.blocks = blocks; this.templateName = templateName; + this._isContext = true; } dust.makeBase = dust.context = function(global, options) { return new Context(undefined, global, options); }; + dust.isContext = function(obj) { + return typeof obj === "object" && obj._isContext === true; + }; + /** * Factory function that creates a closure scope around a Thenable-callback. * Returns a function that can be passed to a Thenable that will resume a @@ -347,7 +352,7 @@ } Context.wrap = function(context, name) { - if (context instanceof Context) { + if (dust.isContext(context)) { context.templateName = name; return context; } diff --git a/test/core.spec.js b/test/core.spec.js index eb730dc2..fcfaa3c1 100644 --- a/test/core.spec.js +++ b/test/core.spec.js @@ -72,6 +72,14 @@ expect(base.options.lang).toEqual(opts.lang); }); }); + + describe('prototype', function() { + var base = dust.context({ + sayHello: function() { return "Hello!"; } + }).push({ foo: 'bar' }); + var context = extend({}, base); + renderIt('survives having its prototype destroyed', '{sayHello} {foo}', context, 'Hello! bar'); + }); }); it("valid keys", function() {