Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question]static property 的支持 #63

Closed
ayqy opened this issue Jul 22, 2017 · 3 comments
Closed

[question]static property 的支持 #63

ayqy opened this issue Jul 22, 2017 · 3 comments

Comments

@ayqy
Copy link

ayqy commented Jul 22, 2017

ESNext 是无法声明 prototype property 的。所以,对于 template / filters / components 等属性,San 提供了 static property 的支持。

实际上不嫌难看的话,可以用ESNext这么搞:

class HelloComponent {
    get template() {
        return '<p>Hello {{name}}!</p>';
    }
    initData() { 
        return {name: 'San'} 
    }
}

// test
HelloComponent.prototype.template && console.log(HelloComponent.prototype.template)
@jinzhubaofu
Copy link
Contributor

现在 san 是通过支持类的静态成员来支持的:

class MyComponent extends san.Component {
  static template = `
    <div>xxxx</div>
  `;
}

当然,需要你自己给 babel 加上插件或者相应的 preset。

@ayqy
Copy link
Author

ayqy commented Jul 23, 2017

san是这样做了没错,只是文档描述ESNext可能不很妥当

@errorrik
Copy link
Contributor

我们并不建议使用 get 来搞。至于描述,我没看出不妥当在哪。static 虽然没有任何运行环境支持,但也属于 ESNext 的一部分。 https://github.com/tc39/proposal-class-fields

如果 @ayqy 觉得不恰当的话,可以在 san-website 的 repo 提 pull-request 咯,这个 issue 我就关了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants