demo/mustache.js
function lookup(name, stack, defaultValue) {
    if (name === ".") {
      return stack[stack.length - 1];
    }

    var names = name.split(".");
    var lastIndex = names.length - 1;
    var target = names[lastIndex];

    var value, context, i = stack.length, j, localStack;
    while (i) {
      localStack = stack.slice(0);
      context = stack[--i];

      j = 0;
      while (j < lastIndex) {
        context = context[names[j++]];

        if (context == null) {
          break;
        }

        localStack.push(context);
      }

      if (context && typeof context === "object" && target in context) {
        value = context[target];
        break;
      }
    }

    // If the value is a function, call it in the current context.
    if (typeof value === "function") {
      value = value.call(localStack[localStack.length - 1]);
    }

    if (value == null)  {
      return defaultValue;
    }

    return value;
  }
function lookup(name, stack, defaultValue) {
    if (name === ".") {
      return stack[stack.length - 1];
    }

    var names = name.split(".");
    var lastIndex = names.length - 1;
    var target = names[lastIndex];

    var value, context, i = stack.length, j, localStack;
    while (i) {
      localStack = stack.slice(0);
      context = stack[--i];

      j = 0;
      while (j < lastIndex) {
        context = context[names[j++]];

        if (context == null) {
          break;
        }

        localStack.push(context);
      }

      if (context && typeof context === "object" && target in context) {
        value = context[target];
        break;
      }
    }

    // If the value is a function, call it in the current context.
    if (typeof value === "function") {
      value = value.call(localStack[localStack.length - 1]);
    }

    if (value == null)  {
      return defaultValue;
    }

    return value;
  }
function lookup ( name , stack , defaultValue ) { if ( name === "." ) { return stack [ stack . length - 1 ] ; } var names = name . split ( "." ) ; var lastIndex = names . length - 1 ; var target = names [ lastIndex ] ; var value , context , i = stack . length , j , localStack ; while ( i ) { localStack = stack . slice ( 0 ) ; context = stack [ -- i ] ; j = 0 ; while ( j < lastIndex ) { context = context [ names [ j ++ ] ] ; if ( context == null ) { break ; } localStack . push ( context ) ; } if ( context && typeof context === "object" && target in context ) { value = context [ target ] ; break ; } } // If the value is a function, call it in the current context. if ( typeof value === "function" ) { value = value . call ( localStack [ localStack . length - 1 ] ) ; } if ( value == null ) { return defaultValue ; } return value ; }
Looks up the value of the given `name` in the given context `stack`.
Looks up the value of the given name in the given context stack .