Преглед изворни кода

Use native Array.isArray when available

tags/0.4.0
Michael Jackson пре 14 година
родитељ
комит
ff543bb74d
1 измењених фајлова са 9 додато и 7 уклоњено
  1. +9
    -7
      mustache.js

+ 9
- 7
mustache.js Прегледај датотеку

@@ -8,6 +8,12 @@ var Mustache = function() {
var regexCache = {};
var Renderer = function() {};

var _toString = Object.prototype.toString;

Array.isArray = Array.isArray || function (obj) {
return _toString.call(obj) == "[object Array]";
}

Renderer.prototype = {
otag: "{{",
ctag: "}}",
@@ -161,14 +167,14 @@ var Mustache = function() {
value = that.find(name, context);

if (type === "^") { // inverted section
if (!value || that.is_array(value) && value.length === 0) {
if (!value || Array.isArray(value) && value.length === 0) {
// false or empty list, render it
renderedContent = that.render(content, context, partials, true);
} else {
renderedContent = "";
}
} else if (type === "#") { // normal section
if (that.is_array(value)) { // Enumerable, Let's loop!
if (Array.isArray(value)) { // Enumerable, Let's loop!
renderedContent = that.map(value, function(row) {
return that.render(content, that.create_context(row), partials, true);
}).join("");
@@ -269,7 +275,7 @@ var Mustache = function() {
}

var value;
// check for dot notation eg. foo.bar
if(name.match(/([a-z_]+)\./ig)){
var childValue = this.walk_context(name, context);
@@ -354,10 +360,6 @@ var Mustache = function() {
return a && typeof a == "object";
},

is_array: function(a) {
return Object.prototype.toString.call(a) === '[object Array]';
},

/*
Gets rid of leading and trailing whitespace
*/


Loading…
Откажи
Сачувај