Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Instance Methods

Christopher Stuart
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Christopher Stuart
Full Stack JavaScript Techdegree Graduate 27,771 Points

ES6 Question

I tried to refactor Andrews code and I have this:

instanceMethods: {
      publishedAt: () => dateFormat(this.createdAt, "dddd, mmmm dS, yyyy, h:MM TT"),

      shortDescription: () => this.body.length > 30 ? this.body.substr(0, 30) + "..." : this.body,
    }

but when I go to the home page i get this error and assuming this is the issue---anyone see a problem with formatting here?

TypeError: C:\Users\crstu\Desktop\JSPROJ\sequelize_blog-start\views\articles\by_line.jade:4 2| = article.author 3| | |

4| = article.publishedAt()

3 Answers

Steven Parker
Steven Parker
229,744 Points

Be sure to let the staff know, using the feedback method described on the Support page.

Ben Zuba
Ben Zuba
13,575 Points

Ran into this same problem new update in sequelize 4. this syntax worked for me

module.exports = (sequelize, DataTypes) => {
  var Article = sequelize.define('Article', {
    title: DataTypes.STRING,
    author: DataTypes.STRING,
    body: DataTypes.TEXT
  }, {});

  Article.associate = function(models) {
    // associations can be defined here
  };

  Article.prototype.publishedAt = function(){
    return dateFormat(this.createdAt, "dddd, mmmm dS, yyyy, h:MM TT");
  };

  Article.prototype.shortDescription = function(){
    return this.body.length > 30 ? this.body.substr(0, 30) + "..." : this.body;
  };

  return Article;
};