Structuring clean Javascript

Status
You're currently viewing only Alexandre's posts. Click here to go back to viewing the entire thread.
Not open for further replies.

Alexandre

Ars Tribunus Militum
1,781
Subscriptor
[url=http:/civis/viewtopic.php?p=25456897#p25456897:1hpw7roe said:
Mile Zero[/url]":1hpw7roe]I have seen people do horrible things with call and function closures for inheritance. The JavaScript mode in Ace does something like this:

Code:
var Mode = function() { /* constructor */ };
(function() {
  this.prototypeProperty = "something";
}).call(Mode.prototype);

They do this because they've already called an inheritance function on the Mode, so they can't just blow away the prototype, and for some ungodly reason they won't just do:
Code:
Mode.prototype.x = y
.

I like Ace, but like any large codebase it has its fair share of WTF moments.
I strongly suggest to not try doing classical inheritance with Javascript. Mixins are a more suitable method for code reutilization with a prototype based language. See http://javascriptweblog.wordpress.com/2 ... pt-mixins/
 
Status
You're currently viewing only Alexandre's posts. Click here to go back to viewing the entire thread.
Not open for further replies.