[Issue] Inheritance from JavaScript object disabled adding new methods to class
See original GitHub issueHi, I try to make adaptation for React
for Brython
(second attempt)
Test html:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="brython.js"></script>
<script src="brython_modules.js"></script>
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
</head>
<body onload="brython(1)">
<script type="text/python" src="lib.py" precompiled></script>
<div id="root"></div>
</body>
</html>
I try to inherit from JS object something like thi
class Hello(window.React.Component):
def __init__(self):
super().__init__(self)
def render(self):
return window.React.createElement('div', None, f"Hello {self.props.toWhat}")
react_obj = Hello()
print(f'react_obj is {dir(react_obj)}')
react_obj.render()
But got the error that there is no such method like render
… but inherited properties are available
When I remove inheritance from JavaScript
object method render
appears on instance of class
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Disable toggle inheritance from parent tag - Stack Overflow
the reason i'm doing this is because i'm using a plugin and i want to add a button looking consistent with the overall...
Read more >Inheritance and the prototype chain - JavaScript | MDN
Calling a function with the new operator returns an object that is an instance of the function. Properties can then be added onto...
Read more >Understanding and Using Prototypical Inheritance in JavaScript
Simply put, prototypical inheritance refers to the ability to access object properties from another object. We use a JavaScript prototype to add ......
Read more >What's the Difference Between Class & Prototypal Inheritance ...
Functional inheritance: In JavaScript, any function can create an object. When that function is not a constructor (or `class`), it's called a factory...
Read more >Object-oriented JavaScript: A Deep Dive into ES6 Classes
Constructors · Keep Data Private · Referring to the Current Object · Static Properties and Methods · Subclasses · Inherit to Avoid Duplication....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@redradist The series of commits above introduce 2 new functions in the
javascript
module :javascript.extends(js_class)
: a decorator meant to be decorate a Python class to transform it into a Javascript class that extends the one passed asjs_class
javascript.super()
: meant to be used in the__init__
method of the subclass. The return value has a single attribute,__init__
, that initializes the parent classYour example works when written with these functions:
For the moment, I prefer to define a specific syntax for this case, instead of using standard Python inheritance (
class Hello(React.Component)
) and the standard built-insuper()
. I’m not sure of all the implications of using the standard Python mechanism for this situation.I am closing the issue, hoping that the result is ok. If not, feel free to reopen it. Thanks @redradist !