question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Model class prototype is undefined

See original GitHub issue

Hi. first of all thank you for this awesome library - it’s amazing! 👍

I wanted to add custom method to the model class, but I’m having problems with accessing to ‘prototype’ property - it’s undefined. Just followed manual, the code below is actually copied over from the doc:

var Sequelize = require('sequelize');

db = new Sequelize('test', 'root', '', {
  host: 'localhost',
  dialect: 'mysql'
});

db.authenticate()
    .then(function(err) {
        debug('Connection has been established successfully.');
    })
    .catch(function (err) {
        debug('Unable to connect to the database:', err);
        process.exit();
    });

var User = db.define('user', { firstname: Sequelize.STRING });

// Adding a class level method
User.classLevelMethod = function() {
  return 'foo';
};

// Adding an instance level method
User.prototype.instanceLevelMethod = function() {  // <---- HERE
  return 'bar';
};```

I have no idea WHY it's undefined... :| To me it looks like not up to date manual or some bug.

sequelize: 3.23.6
nodejs: 6.2.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

23reactions
janmeiercommented, Aug 2, 2016

The docs are for 4.0 - for 3.0, you need to do `User.Instance.prototype

0reactions
cojackcommented, Sep 30, 2017

@janmeier you’re f*** right, sorry :<

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is JavaScript prototype property undefined on new objects?
Because prototype is a property of functions (actually, constructors), since it defines the properties/methods of objects of this class ...
Read more >
Inheritance and the prototype chain - JavaScript | MDN
While classes abstract most of the prototypical mechanism away, ... undefined, because d doesn't inherit from Object.prototype
Read more >
Prototype in JavaScript - TutorialsTeacher
The prototype is an object that is associated with every functions and objects by default in JavaScript, where function's prototype property is accessible ......
Read more >
Javascript Prototype & Scope Chains: What You Need to Know
When using prototypal inheritance, remember to define properties in the prototype after having either inherited from the parent class or specified an ...
Read more >
Prototype in JavaScript: it's quirky, but here's how it works
[[Prototype]]: This is a somehow-hidden property on every object which is accessed by the running context if some property which is being read ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found