Comments (8)
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.
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.
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.
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.
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.
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.
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.
That's great @tnhu, thanks!
from jsface.
Related Issues (20)
- Overload the default constructor HOT 1
- Introduce Class.create() function HOT 3
- Maximum call stack size exceeded when C extends B and B extends A HOT 2
- Undefined is not an object | Exporting a Node.js Module HOT 2
- Error using EventEmitter api
- instanceof does not work for jsface HOT 2
- Documentation of $superp HOT 2
- Add cdn info HOT 4
- Static methods are inherited across all instances HOT 3
- $statics do not work HOT 1
- Invalid CDN link HOT 1
- Super's constructor not getting called if sub class not defining constructor (yes, again). HOT 3
- noConflict does not solve all conflicts HOT 3
- requirejs + jsface problem HOT 2
- Uncaught ReferenceError: extend is not defined HOT 3
- getters & inheritance don't work (gets evaluated while inheriting) HOT 1
- Inherit from javascript function HOT 1
- Nested objects extending
- Cannot call a class as a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsface.