shannonmoeller / handlebars-layouts

Handlebars helpers which implement layout blocks similar to Jinja, Nunjucks (Swig), Pug (Jade), and Twig.
http://npm.im/handlebars-layouts
MIT License
361 stars 29 forks source link

TypeError: arg.hasOwnProperty is not a function #27

Closed joonas-lahtinen closed 9 years ago

joonas-lahtinen commented 9 years ago

When used together with Express.js and when passing res.locals as the template context which uses handlebars-layouts, the following error happens:

TypeError: arg.hasOwnProperty is not a function
    at mixin ([snip]/node_modules/handlebars-layouts/index.js:72:12)

As can be seen from the code, hasOwnProperty is expected to be a function in the objects:

if (arg.hasOwnProperty(key)) {
    target[key] = arg[key];
}

But this is not the case with Express.js:

// express/lib/middleware/init.js
res.locals = res.locals || Object.create(null);

Where the prototype of the res.locals is not Object.

shannonmoeller commented 9 years ago

What is the value of arg at that point?

joonas-lahtinen commented 9 years ago

Value is res.locals from Express.js, I sent a PR for the change required and added tests for it.