11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CoffeeScriptでObject.definePropertyを使ってみた

Posted at

CoffeeScript Issue #1165によるとObject.definePropertyは当分実装されない模様。少々強引ですが面白やり方を見つけましたのでここに記入します。

ぶっちゃけObjectice-Cの@propertyみたいに@synthesis出来たらいいなって思ってます。

Function::property = (prop, desc) ->
  Object.defineProperty @prototype, prop, desc

class Fuga
  constructor: (@_foo='bar') ->
  @property 'foo',
    get: -> @_foo
    set: (foo) -> @_foo = foo

f = new Fuga 'Nyaa'
console.log p.foo
f.foo = 'Nyo'
console.log p.foo

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?