lukehaas / RunJS

RunJS is a JavaScript playground for macOS, Windows and Linux. Write code with instant feedback and access to Node.js and browser APIs.
https://runjs.app
2.01k stars 44 forks source link

装饰器Decorator error #634

Closed amandaXCY closed 4 days ago

amandaXCY commented 3 weeks ago

function observable(fnName:any) { // 装饰器工厂函数 return function (target: any, key: string): any { console.log(1,target)// 装饰器 console.log(2,key)// 装饰 let prev = target[key];

Object.defineProperty(target, key, {
  set(next) {
    target[fnName](prev, next);
    prev = next;
  }
})

} }

class Store { @observable('onCountChange') count = -1; }

const store = new Store(); store.count = 10

out

1 undefined 2 { kind: 'field', name: 'count', metadata: [Object: null prototype] {}, addInitializer: ƒ bound (), static: false, private: false, access: { has: ƒ (), get: ƒ k(), set: ƒ F() } }

but in https://www.typescriptlang.org/play/

LOG: 1, Store: {}

node packs: babel/core:7.24.5 babel/preset-env:7.24.7

lukehaas commented 2 weeks ago

Thanks @amandaXCY. I'm seeing the same result in both RunJS and the typescript playground:

Screenshot 2024-07-09 at 09 41 18

Screenshot 2024-07-09 at 09 41 10

What version of RunJS are you using?

lukehaas commented 4 days ago

Closing as there's not been a response from @amandaXCY 😔