获取 CoffeeScript 对象的所有实例方法
我有一个 CoffeeScript 对象,我想获取它的所有实例方法。
有没有简单的方法可以做到这一点?
I have a CoffeeScript object and I want to get all of its instance methods.
Is there an easy way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得所有实例方法,因为它们现在使用以下 CoffeeScript 代码:
@thejh 的解决方案将为您提供的不仅仅是函数,并且不能在所有 JS 平台上工作,但在其他方面是正确的。另请注意,CoffeeScript 对象是 JavaScript 对象——实际上没有区别。
You can get all of the instance methods as they are now using the following CoffeeScript code:
@thejh's solution will give you more than just functions and doesn't work in all JS platforms, but is otherwise correct. Also note that a CoffeeScript object is a JavaScript object -- there's no distinction, really.
<一href="http://coffeescript.org/#try%3aclass%20Foo%0A%0A%20%20m%3a%20-%3E%201%0A%0Aob%20=%20new%20Foo%0A%0A% 0A实例方法ds%20=%20%28v%20for%20k,%20v%20of%20ob%20当%20typeof%20v%20为%20%22function%22%29%0A%0Aconsole.log%20instanceMethods%0A" rel="nofollow">看这个
See this