Editor constructor

Editor constructor

perrotinperrotin Posts: 39Questions: 9Answers: 1

Hi Allan,

I've got a little issue that I really don't understand the reason.

I'm using editor PHP server-side on two different environnement (production and developement)

I'm initializing editor with the usual :

var editor = new $.fn.DataTable.Editor(.... );

At one point in my code I need to check if this object is an editor object or not
(in a function I pass as argument either options object to initialize the editor or editor object itself )

To determine if object is an editor I use
editor.constructor.name == 'Editor'

On dev. environnement this is true, but on prod. environnement it returns false.
It appears that the value returned for editor.constructor.name is "f"
I check right after the initialisation of the object an result is still "Editor" on dev. and "f" on prod.

What's even stranger is that the editor object is working fine on both environnement
The options passed to editor are the same, the browser is the same, and yet editor.constructor.name doesn't return "Editor"

Any idea why this happens, and do you have another solution to check if the object is an editor object

Thanks for your help

Replies

  • allanallan Posts: 61,648Questions: 1Answers: 10,093 Site admin

    I would suggest using instanceof to check if an object is an Editor object or not:

    if ( editor instanceof $.fn.DataTable.Editor ) {
      ...
    }
    

    If you want to check that it is not an instance of, be slightly careful - you have to use backets as ! takes higher presidence than instanceof (I've fallen into that trap myself):

    if ( ! (editor instanceof $.fn.DataTable.Editor) ) {
      ...
    }
    

    The MDN documentation (as always) is excellent on this topic.

    The f you are seeing probably comes from whatever minification you are using on production.

    Allan

This discussion has been closed.