3

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'
3
  • When I want to get it from array can we see that code portion? Commented May 15, 2013 at 15:16
  • There's identation missing in name = null and getHtml: ->. Like this, these statements are not part of the class definition! Commented May 15, 2013 at 15:20
  • It was also hard to diagnose because you were not accessing name you were assigning to i,t therefore creating a new property... Commented May 15, 2013 at 15:42

1 Answer 1

1

You probably mean to indent the name and getHtml definitions:

exports.textareaWidget = class textareaWidget
  name: null    
  getHtml: ->
        this.generateHtml(widgetHtml)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.