Coder Social home page Coder Social logo

Comments (8)

visionscaper avatar visionscaper commented on July 18, 2024

Hi @tnhu,

Were you able to check out this bug? It seems to be introduced with fixing #20.
You added the following line:
clazz.prototype = classOrNil(parent[0]) ? new parent[0] : parent[0];

When classOrNil returns true this evaluates the constructor of the parent class while the class is actually not constructed at that point in time but merely defined.

Please let me know what you think!

from jsface.

visionscaper avatar visionscaper commented on July 18, 2024

Hi again @tnhu,

I solved this issue myself. By replacing in jsface.js :

clazz.prototype = classOrNil(parent[0]) ? new parent[0] : parent[0];

by

clazz.prototype.__proto__  = classOrNil(parent[0]) ? parent[0].prototype : parent[0];

Can you replace it in your code? Or should I send a pull request?

Cheers,

-- Freddy Snijder

from jsface.

tnhu avatar tnhu commented on July 18, 2024

Hi Freddy,

Thanks for reporting. I apologize for being super late. Been terribly busy with work so do not have time to look into jsface bugs. I probably have some time mid-next week. I'll try to find a fix for this by then.

Your solution could not work across platform since __proto__ is not a standardized property.

Again, very sorry for the late!

Tan

from jsface.

visionscaper avatar visionscaper commented on July 18, 2024

Hi Tan,

Thanks for reacting. You are right, proto is not (yet) a standardised property.

I did a quick test and this works as well (not using proto):

var __inherit = function(childClass, parentClass) {
    var f=function(){}; // defining temp empty function
    f.prototype=parentClass.prototype;
    f.prototype.constructor=f;

    childClass.prototype=new f;

    childClass.prototype.constructor=childClass; // restoring proper constructor for child class
    parentClass.prototype.constructor=parentClass; // restoring proper constructor for parent class
};

if (classOrNil(parent[0])) {
    __inherit(clazz, parent[0]);
} else {
    clazz.prototype = parent[0];
}

I'm looking forward to see the final fix!

-- Freddy Snijder

from jsface.

tnhu avatar tnhu commented on July 18, 2024

I have a better patch, can you apply it and see if it works for you?

    if ( !singleton && len) {
      var parentClass = classOrNil(parent[0]);

      if ( !parentClass) {
        clazz.prototype = parent[0];
      } else {
        for (var key in parentClass) {
          if ( !ignoredKeys[key]) {
            clazz.prototype[key] = parentClass[key];
          }
        }
      }
      clazz.prototype.constructor = clazz;
    }

from jsface.

visionscaper avatar visionscaper commented on July 18, 2024

Hi @tnhu,

I'm sorry, no not completely. Although this issue is solved with that code, it does break issue #20 again. I tested my last solution (and my first solution) by trying to recreate this issue and issue #20 and running the sample code in your readme.md. My solutions did work, for this issue and for issue #20.

Good luck!

Cheers,

FS

from jsface.

tnhu avatar tnhu commented on July 18, 2024

Hi Freddy, Thanks for the fix. I merged your solution into 2.4.0. Credit on CHANGELOG :) Let me know you found anything else.

Tan

from jsface.

visionscaper avatar visionscaper commented on July 18, 2024

That's great @tnhu, thanks!

from jsface.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.