Skip to content

Commit 07b73b3

Browse files
authored
Merge pull request #744 from sethkinast/is-context
Don't use instanceof to determine if a Context is a Context. Instead use a flag on the instance itself so it can survive object merges.
2 parents dc1e1dc + ae69314 commit 07b73b3

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/dust.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,17 @@
328328
this.options = options;
329329
this.blocks = blocks;
330330
this.templateName = templateName;
331+
this._isContext = true;
331332
}
332333

333334
dust.makeBase = dust.context = function(global, options) {
334335
return new Context(undefined, global, options);
335336
};
336337

338+
dust.isContext = function(obj) {
339+
return typeof obj === "object" && obj._isContext === true;
340+
};
341+
337342
/**
338343
* Factory function that creates a closure scope around a Thenable-callback.
339344
* Returns a function that can be passed to a Thenable that will resume a
@@ -347,7 +352,7 @@
347352
}
348353

349354
Context.wrap = function(context, name) {
350-
if (context instanceof Context) {
355+
if (dust.isContext(context)) {
351356
context.templateName = name;
352357
return context;
353358
}

test/core.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@
7272
expect(base.options.lang).toEqual(opts.lang);
7373
});
7474
});
75+
76+
describe('prototype', function() {
77+
var base = dust.context({
78+
sayHello: function() { return "Hello!"; }
79+
}).push({ foo: 'bar' });
80+
var context = extend({}, base);
81+
renderIt('survives having its prototype destroyed', '{sayHello} {foo}', context, 'Hello! bar');
82+
});
7583
});
7684

7785
it("valid keys", function() {

0 commit comments

Comments
 (0)