"Proper" OO Inheritance for JavaScript
... this is the subject of a post by juerg leny to the helma mailing list.
Juerg and Hannes attemted (independendly) to improve an approach by Dean Edwards.
Dean meantions a few goals:
A second parameter passed to the extend method of a class defines the class interface
But i don't like the syntax too much. The main problem i have is that reading the example above it's hard to figure out which of the two arguments is the static hash and which one the class methods. And in most languages static properties are declared at the beginning of a class, because in most cases they will be used in the class methods.
Something like this would be more readable:
Some more links:
more Dean Edwards
Sam does like Deans approach
The $class library
$class example
Juerg and Hannes attemted (independendly) to improve an approach by Dean Edwards.
Dean meantions a few goals:
- I want to easily create classes without the MyClass.prototype cruft
- I want method overriding with intuitive access to the overridden method (like Java’s super)
- I want to avoid calling a class’ constructor function during the prototyping phase
- I want to easily add static (class) properties and methods
A second parameter passed to the extend method of a class defines the class interface
var MyClass = Base.extend({
foo: "value",
someFunction: function() { }
}, {
PI: 3.14
})
Having extendable "classes" and interfaces makes it a lot easier to write reuseable and extendable code in Javascript. Which is a must for Helma(2).But i don't like the syntax too much. The main problem i have is that reading the example above it's hard to figure out which of the two arguments is the static hash and which one the class methods. And in most languages static properties are declared at the beginning of a class, because in most cases they will be used in the class methods.
Something like this would be more readable:
var MyClass = Base.extend({
ONE: 'One',
$methods: {
one: function() { }
}
});
In this example all properties of the hash (which is the only argument) are becoming static properties of the "class" except the children of hash "$methods". "$methods" could also be called "prototype" which is the standard naming in Javascript.Some more links:
more Dean Edwards
Sam does like Deans approach
The $class library
$class example
matthias - 5. Sep, 16:58
2 comments - add comment - 0 trackbacks








