I was wondering how one would go about making “classes” similar to those in Python in Javascript. Take the Python classes and functions listed here:
class one:
def foo(bar):
# some code
The function “foo” would be called with one.foo(bar).
What would the JS equivalent be? I suspect it would be something like this:
var one = {
foo: function(bar) {
// JavaScript
}
};
Thanks.
The native way to create classes in Javascript is to first define the constructor:
and a prototype:
Then you can create instance of MyClass:
Add static methods:
Extend MyClass: