baidu / san

A fast, portable, flexible JavaScript component framework
https://baidu.github.io/san/
MIT License
4.72k stars 549 forks source link

模板的方法调用不支持 click()() 方式 #702

Closed donghualei closed 2 years ago

donghualei commented 2 years ago

代码如下:

    static template = `
        <div>
            <div>{{ writeA('writeB')(msg) }}</div>
        </div>
    `
writeA(m) {
        return this[m];
    }

    writeB(text) {
        return text + 'world';
    }

渲染后的结果为: <div>function writeB(text) {return text + 'world';}</div>

是否有必要支持这种模式呢?

errorrik commented 2 years ago

我没搞懂你这么搞的原因,method call 是支持多级的。

var MyApp = san.defineComponent({
  template: `<div>
    {{fs[method](text)}}
  </div>`,

  fs: {
    up(text) {return text.toUpperCase()},
    lower(text){return text.toLowerCase()}
  }
})
var myApp = new MyApp({
  data: {
    method: 'up',
    text: 'Hello'
  }
});
myApp.attach(document.body)