backbone.js - Exporting a function with RequireJS in Node returns an empty object -


how export function requirejs module in node? code have, empty object rather backbone model i'm expecting.

first.js contains:

'use strict'; var define=require('amd-define'); define(function (require) {  var backbone = require('backbone');  // our basic **todo** model has `title`, `order`, , `completed` attributes. var todo = backbone.model.extend({     // customizations of model... });  return todo; }) 

my test file test.js contains:

'use strict'; var chai =require("chai"); var assert=chai.assert; var expect=chai.expect; var todo=require("first");  describe('tests todo model', function () {     it('should create global variables todo', function () {         expect(todo).to.be.exist;         console.log(typeof (todo))     });      it('should created default values attributes',               function() {         var todo = new todo();         expect(todo.get('title')).to.equal('');     });      it('should fire custom event when state change', function() {         var todo = new todo();         todo.set({completed: true, order: 1});         todo.set('title', 'my title');     }); }); 

it gives error todo not function. console.log statement prints object.

the package amd-define either buggy or not support commonjs sugar. (the latter case. not see code in takes care of doing dependency transformation necessary supporting commonjs sugar.)

i recommend dumping amd-define , using amd-loader instead. i've used years, works.

for code:

  1. remove var define=require('amd-define'); first.js.

  2. add require('amd-loader') (after installing it) in test file before load amd module.

i able export first.js doing this.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -