diff --git a/packages/blaze/builtins.js b/packages/blaze/builtins.js index 18e165c09..21fcd21eb 100644 --- a/packages/blaze/builtins.js +++ b/packages/blaze/builtins.js @@ -1,5 +1,5 @@ Blaze._calculateCondition = function (cond) { - if (cond instanceof Array && cond.length === 0) + if (HTML.isArray(cond) && cond.length === 0) cond = false; return !! cond; }; diff --git a/packages/html-tools/parse.js b/packages/html-tools/parse.js index 109e9fa2f..7b3296327 100644 --- a/packages/html-tools/parse.js +++ b/packages/html-tools/parse.js @@ -187,7 +187,7 @@ getContent = HTMLTools.Parse.getContent = function (scanner, shouldStopFunc) { // as in `FOO.apply(null, content)`. if (content == null) content = []; - else if (! (content instanceof Array)) + else if (! HTML.isArray(content)) content = [content]; items.push(HTML.getTag(tagName).apply( diff --git a/packages/htmljs/html.js b/packages/htmljs/html.js index ce758772d..55c8adac2 100644 --- a/packages/htmljs/html.js +++ b/packages/htmljs/html.js @@ -171,10 +171,7 @@ Raw.prototype.htmljsType = Raw.htmljsType = ['Raw']; HTML.isArray = function (x) { - // could change this to use the more convoluted Object.prototype.toString - // approach that works when objects are passed between frames, but does - // it matter? - return (x instanceof Array); + return x instanceof Array || Array.isArray(x); }; HTML.isConstructedObject = function (x) { @@ -185,10 +182,22 @@ HTML.isConstructedObject = function (x) { // if you assign to a prototype when setting up the class as in: // `Foo = function () { ... }; Foo.prototype = { ... }`, then // `(new Foo).constructor` is `Object`, not `Foo`). - return (x && (typeof x === 'object') && - (x.constructor !== Object) && - (typeof x.constructor === 'function') && - (x instanceof x.constructor)); + if(!x || (typeof x !== 'object')) return false; + // Is this a plain object? + let plain = false; + if(Object.getPrototypeOf(x) === null) { + plain = true; + } else { + let proto = x; + while(Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto); + } + plain = Object.getPrototypeOf(x) === proto; + } + + return !plain && + (typeof x.constructor === 'function') && + (x instanceof x.constructor); }; HTML.isNully = function (node) {