Export commonLogic functions to external javascript class/function


I am trying to move some common logic from multiple of my models in NativeScript to one seperate file that I want to require in my models. I don’t have any Javascript experience and wanted to make a class like you’d do in Java however this appearantly doesn’t work.

Can anybody explain what goes wrong and how I’d have to go about this?

This is what I currently have (example code):


function Person(lastName, firstName)
this.firstName = firstName;
this.lastName = lastName;


var Person = require("~/CommonLogic");

exports.loaded = function(args) {
var person = new Person(‘Clouseau’, ‘Jacques’);
console.log('The person is ’ + person);


System.err: Calling js method onCreateView failed
System.err: TypeError: Person is not a constructor

Thanks in advance!

Answered on stackoverflow: https://stackoverflow.com/questions/49879591/javascript-class-function-in-nativescript