0

I have a object with function

{
 ready(_callback) {
     _callback();
 },
 Map() {
     this.geoObjects = () => {
         return {
            add() {},
            get() {
                return {
                    removeAll() {},
                    add() {},
                };
            },
        }
    };
    this.setCenter = () => {};
    this.setZoom = () => {};
 },
},

an then I write

Map: function () { // it is a constructor
Map() { // it is not a constructor
Map: () => { //it is not a constructor

Why? Help pls. And how to write this object with a constructor function on ES6 format?

  • 1
    method and arrow function syntax results in a function that's not constructable. You just need a normal function. – VLAZ Dec 09 '20 at 06:48
  • 1
    The answer is found here: [How to check if a Javascript function is a constructor](https://stackoverflow.com/q/40922531) although the question goes in a different angle. Still, the answers do a good job explaining what is constructable and what isn't. – VLAZ Dec 09 '20 at 06:53
  • 1
    `class`, function expressions and function declarations create constructable functions. Everything else does not. – Felix Kling Dec 09 '20 at 15:35

0 Answers0