为什么Knockoutjs使用""声明和"新功能"实现其bindingProvider?

时间:2015-09-09 02:41:06

标签: javascript angularjs mvvm binding vue.js

为什么不在angularjs或正则表达式中使用vue替换解析器?哪一个更好?是否可以使用"使用"声明?

Konckoutjs

function createBindingsStringEvaluator(bindingsString, options) {
    // Build the source for a function that evaluates "expression"
    // For each scope variable, add an extra level of "with" nesting
    // Example result: with(sc1) { with(sc0) { return (expression) } }
    var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString, options),
        functionBody = "with($context){with($data||{}){return{" + rewrittenBindings + "}}}";
    return new Function("$context", "$element", functionBody);
}

Angularjs

  var Parser = function(lexer, $filter, options) {
      this.lexer = lexer;
      this.$filter = $filter;
      this.options = options;
      this.ast = new AST(this.lexer);
      this.astCompiler = options.csp ? new ASTInterpreter(this.ast, $filter) :
      new ASTCompiler(this.ast, $filter);
  };
  ...

VUE

  function compileExpFns (exp, needSet) {
      if (improperKeywordsRE.test(exp)) {
          process.env.NODE_ENV !== 'production' && _.warn(
          'Avoid using reserved keywords in expression: ' + exp)
      }
      // reset state
      saved.length = 0
      // save strings and object literal keys
      var body = exp
          .replace(saveRE, save)
          .replace(wsRE, '')
      // rewrite all paths
      // pad 1 space here becaue the regex matches 1 extra char
      body = (' ' + body)
          .replace(pathReplaceRE, rewrite)
          .replace(restoreRE, restore)
      ...
  }

1 个答案:

答案 0 :(得分:0)

根据JavaScript’s with statement and why it’s deprecated,JR microtemplate没有安全和性能问题,因为所有属性仅用于输出。

仅供参考Are there legitimate uses for JavaScript's “with” statement?