简体   繁体   English

数组中的Coffeescript类对象

[英]Coffeescript class object in array

I have some class with some functions and properties 我有一些具有一些功能和属性的类

exports.textareaWidget = class textareaWidget extends Widget
name = null    
getHtml: ->
        this.generateHtml(widgetHtml)

Then I create an object and add to array: 然后我创建一个对象并添加到数组:

    obj = new w.textareaWidget()
    obj.name = "msgBody"
    console.log obj.getHtml() # works
    arr.push(obj)
# getting from arr
for field in arr
  result = result + field.getHtml()

When I want to get it from array I can access properites (name) but I can't access functions (getHtml). 当我想从数组中获取它时,我可以访问属性(名称),但我无法访问函数(getHtml)。 Why and how can I make it working ? 为什么以及如何使其正常工作? The error: 错误:

TypeError: Object #<Object> has no method 'getHtml'

You probably mean to indent the name and getHtml definitions: 你可能意味着缩进namegetHtml定义:

exports.textareaWidget = class textareaWidget
  name: null    
  getHtml: ->
        this.generateHtml(widgetHtml)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM