user761100 user761100 - 2 months ago 4x
Javascript Question

Trouble defining Constructor in Javascript

I have a Javascript object in common.js file:

var KITS=
debug: false,
default_country : 'xxx',
franchise : ''

var self = this;
// ...

if (typeof cb==='function') (cb)();

if (typeof cb==='function') (cb)();

I include this js file in a php file. Could some expert please advise what I need to do so that KITS.init() is automatically called when the KITS object is created?


Object literals are not created with new, so they wouldn't trigger the constructor even if they had one. They do not have constructors, thanks to not having a prototype of their own:

const foo = {
  a: 1,
  b: 2