Uncaught TypeError: object is not a function when inheriting from Node using Famous-Engine

162 views Asked by At

My code looks like this

var DOMElement = require('famous/dom-renderables/DOMElement');
var FamousEngine = require('famous/core/FamousEngine');
var Transitionable = require('famous/transitions/Transitionable');
var Node = require('famous/core/Node');
function Card() {
  Node.call(this);
  this.setAbsoluteSize(250, 250);
  this.setSizeMode('absolute', 'absolute');
  this.setPosition(FIRST_X_POSITION, Y_POSITION);
  this.nodeDomElement = new DOMElement(this);
  this.nodeDomElement.setProperty('backgroundImage', 'url(images/tile-03.png)');
  this.nodeDomElement.setProperty('background-color', '#9a105f');
}


Card.prototype = Object.create(Node.prototype);
Card.prototype.constructor = Card;

and I am calling it as follows

var Card = require('./Card.js');
var firstNode = this.rootNode.addChild(new Card());

but I am getting the following error

Uncaught TypeError: object is not a function
1

There are 1 answers

0
talves On BEST ANSWER

Make sure to set your exports for the new Card class.

module.exports = Card;

var DOMElement = require('famous/dom-renderables/DOMElement');
var FamousEngine = require('famous/core/FamousEngine');
var Transitionable = require('famous/transitions/Transitionable');
var Node = require('famous/core/Node');

function Card() {
  Node.call(this);
  this.setAbsoluteSize(250, 250);
  this.setSizeMode('absolute', 'absolute');
  this.setPosition(FIRST_X_POSITION, Y_POSITION);
  this.nodeDomElement = new DOMElement(this);
  this.nodeDomElement.setProperty('backgroundImage', 'url(images/tile-03.png)');
  this.nodeDomElement.setProperty('background-color', '#9a105f');
}


Card.prototype = Object.create(Node.prototype);
Card.prototype.constructor = Card;

module.exports = Card;