GithubHelp home page GithubHelp logo

Comments (7)

otakustay avatar otakustay commented on July 23, 2024

babel repl来看是可以的,包括在非方法的属性上使用也是可以的

对象直接量会使用在2种场景:

  1. 一个带逻辑的对象,可能是一个模块的export
  2. 一个纯对象,只是数据的

我们比较担心第2种情况下的滥用,在此先做比较严格的限制,在确定了一些实践的指导后再考虑改吧

from spec.

hax avatar hax commented on July 23, 2024

举个例子:

const o = {
  @nonenumerable test() {...}
}

这样的用途并没有什么不妥当啊。

from spec.

otakustay avatar otakustay commented on July 23, 2024

在方法上声明我觉得OK,但是在一个纯数据型的object上把装饰器丢property上我反对

这条可以改成不得在对象的property上添加装饰器

from spec.

hax avatar hax commented on July 23, 2024

我就是写了:

const test = {
  @readonly test: 'You should not change me!'
}

为什么不可以呢?

当然我理解作为data的plain object似乎应该保持简单,但是到底是不是plain object,这个不是检查能检查出来的呀。

from spec.

otakustay avatar otakustay commented on July 23, 2024

@errorrik 我想了一下,这条我们这么说不知是否合适

不在作为纯数据使用的对象上使用装饰器

这里需要对“纯数据”作一个定义,我理解是只承载属性且使用场景仅限于hasOwnProperty.foo.foo = barfor in等对plain object的操作的

from spec.

hax avatar hax commented on July 23, 2024

@otakustay 然而我上面这个例子代码并不会影响它作为纯数据被使用。

担心被滥用,首先得有滥用的case,否则不清楚原因就禁止,以后可能会变成讲不清楚的历史遗留习惯。。。

from spec.

errorrik avatar errorrik commented on July 23, 2024

纯数据是一个很难被静态检查的定义诶。

decorator现在还不太成熟,我觉得这条不如暂时去掉,等看大家实践看看有没坑。对于这点,现在我没想出大家能玩出坑来,我甚至觉得大家应该都不会玩的。

from spec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.