简体   繁体   中英

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). 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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