Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use instanceof to determine if a Context is a Context #744

Merged
merged 1 commit into from
Sep 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -347,7 +352,7 @@
}

Context.wrap = function(context, name) {
if (context instanceof Context) {
if (dust.isContext(context)) {
context.templateName = name;
return context;
}
Expand Down
8 changes: 8 additions & 0 deletions test/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down