stackgl / headless-gl

🎃 Windowless WebGL for node.js
1.76k stars 169 forks source link

gl.constructor.name is a bound function name #184

Open psychobolt opened 4 years ago

psychobolt commented 4 years ago

Hi I recently updated gl 4.3.3 to gl 4.4.0. I have code that checks the type of object to initialize a regl object. Currently in 4.4.0, gl.constructor.name returns "bound WebGLRenderingContext", where in 4.3.0 gl.constructor.name returns "WebGLRenderingContext". I assume in 4,4.0, constructor is being binded, I wonder if that is a ideal case or issue.

psychobolt commented 4 years ago

My workaround:

Object.defineProperty(ctx.constructor, 'name', { value: 'WebGLRenderingContext' });
dhritzkiv commented 4 years ago

Sorry for the seemingly breaking change! This change was part of the effort to update the library for ES6+ code standards, to make it more maintainable for. Definitely didn't consider this unintended consequence.

Thanks for posting your workaround!

However, It's unlikely we'll address this, unless the fix is as simple as:

//...
      if (privateMethods.indexOf(prop) === -1) {
        wrapper[prop] = value.bind(privateInstance)

        // rename bound property
        Object.defineProperty(wrapper[prop], 'name', { value: 'prop' });
      }
//...

…and doesn't have any side effects