I changed the syntax of the
Mocha Inheritance
code a bit, to what I think you'll agree is easier to read:
Function.prototype.inherit = function(fnc) {
var constr = this;
var Constructor = function(){
if (fnc)
fnc.apply(this, arguments);
constr.apply(this, arguments);
};
Constructor.prototype = new (fnc || this)();
Constructor.prototype.constructor = fnc || this;
return Constructor;
};
Prototype inheritance reduced to the max :-)
15.1.2007, 10:01
|
In its current incarnation, Javascript prototype inheritance has some shortcomings. In particular, prototypes do not inherit their parent's constructor and methods in child prototypes can not dynamically access an inherited method they override.
After
Hannes'
and
Jürg's
suggestions for improvements to Dean Edwards'
Base Class
approach to Javascript inheritance, I made an attempt to solve the problem by focusing more intensely on fixing Javascript's prototype inheritance than adding class sugar around it.
What I came up with is this:
| name |
type |
size |
|
mocha.js
|
application/x-javascript |
1311 bytes |
|
mocha.html
|
text/html |
1942 bytes |
Mocha Inheritance does its magic in these 20 lines of code:
Function.prototype.inherit = function(inherit) {
var fnc = inherit ? this : function(){};
inherit = inherit || this;
var Constructor = function(){
inherit.apply(this, arguments);
fnc.apply(this, arguments);
};
Constructor.prototype = new inherit();
Constructor.prototype.constructor = inherit;
return Constructor;
};
Function.prototype.applySuper = function(method,obj,args) {
var that = this;
do {
if (that.prototype[method] && that.prototype[method] != obj[method])
return that.prototype[method].apply(obj,args);
that = that.prototype.constructor;
} while (that != Object);
};
Creating a new prototype "Mensch" with mocha inheritance from "Animal":
var Mensch = Animal.inherit();
Letting a previously created constructor "Mensch" mocha inherit from "Animal":
Mensch = Mensch.inherit(Animal);
And here an example of a Mensch method "evolve" that overrides what it inherits from Animal, but still manages to do nothing different:
Mensch.prototype.evolve = function(){
return this.constructor.applySuper('evolve', this, arguments);
}
With some more syntactic sugar around it, I think this is quite a nice approach.
http://dev.helma.org/wiki/Mocha+Inheritance/
12.1.2007, 13:20
|
Helma 1.5.3 makes dynamically loaded code repositories available immediately after the app.addRepository() statement and offers improved logging behavior along with several small bug fixes.
http://helma.org/download/
http://helma.org/download/changelog/1.5.3/
15.11.2006, 19:27
|
The 5th edition of
David Flanagan
's Javascript - The Definitive Guide is
now also available on Safari
and I have it on my online bookshelf :-)
I must admit that when I started reading the 5th edition, I quickly started to look forward to the 6th edition, although the 5th edition is well worth getting for anybody that works with Javascript.
The 5th edition seems to do some selective catching up and shies away even from Javascript 1.6 additions that look certain to be part of ECMA-262 version 4. Apparently, David Flanagan drew a carfully drafted line for what he wanted to include in the 5th edition and was thinking ahead to the 6th edition already. That's not a bad thing, of course. The result is a very clean 5th edition.
Too bad E4X ended up getting buried in the Client-Side section. I hope the 6th edition will treat it as an extension to Core Javascript instead. Hopefully, including mentioning it in the Literals section and in chapter 3, even-though it is an optional "standard extension".
One of the things that makes this book so great is the fact that it cleanly separates between the browser/client side and the core language, making it the best companion when working in
Rhino based environments on the server-side such as Helma
.
Naturally, when working in an environment like Helma, the limitations on using the newest language extensions do not apply, and the 5th edition doesn't quite cater to this niche as well as it could.
So, basically, I hope for a bit more "Rhino" in the 6th edition of the "Rhino book" ;-) ...and maybe even a chapter on existing server-side frameworks.
1.9.2006, 12:38
|
The belgian group
Hooverphonic
was clearly the highlight of
this years
Mont-Soleil
Open Air Festival
! I already really liked their last album
No More Sweet Music
, but seeing them perform live was even more impressive. Unlike many groups these days, which can't match the quality of their recordings outside the studio, Hooverphonic's performance was excellent!
28.8.2006, 15:45
|
Hot on the heels of Helma 1.5.1 and in order to
clear the slate
for Helma/Rhino 1.6, which will bring us E4X support amongst other goodies,
Helma 1.5.2 has been released
, fixing a potentially annoying error logging issue.
18.8.2006, 18:45
|
From
RFC 4329 - Scripting Media Types
...
Various unregistered media types have been used in an ad-hoc fashion
to label and exchange programs written in ECMAScript and JavaScript.
These include:
+-----------------------------------------------------+
| text/javascript | text/ecmascript |
| text/javascript1.0 | text/javascript1.1 |
| text/javascript1.2 | text/javascript1.3 |
| text/javascript1.4 | text/javascript1.5 |
| text/jscript | text/livescript |
| text/x-javascript | text/x-ecmascript |
| application/x-javascript | application/x-ecmascript |
| application/javascript | application/ecmascript |
+-----------------------------------------------------+
Use of the "text" top-level type for this kind of content is known to
be problematic. This document thus defines text/javascript and text/
ecmascript but marks them as "obsolete". Use of experimental and
unregistered media types, as listed in part above, is discouraged.
The media types,
* application/javascript
* application/ecmascript
which are also defined in this document, are intended for common use
and should be used instead.
This document defines equivalent processing requirements for the
types text/javascript, text/ecmascript, and application/javascript.
Use of and support for the media type application/ecmascript is
considerably less widespread than for other media types defined in
this document. Using that to its advantage, this document defines
stricter processing rules for this type to foster more interoperable
processing.
17.8.2006, 11:03
|
|
|
> Aptana - Eclipse reincarnated as a Javascript IDE
|
|
> Building the Conversational Web
|
|
> Drosera steps in to debug Safari
|
|
> Helma 1.5.0 has been released!
|
|
> Helma 1.5 RC2 is ready
|
|
> Helma 1.5.0 Release Candidate 1 available for download
|
|
> FreeBSD Jails the brand new easy way
|
|
> Javascript 2 and the Future of the Web
|
|
> Frodo takes on chapter 3
|
|
> No Rough Cut :-(
|
|
> Welcome to Helma!
|
|
> 40th Montreux Jazz Festival
|
|
> trackAllComments
|
|
> Rails' greatest contribution
|
|
> Consensus vs Direct Democracy
|
|
> A candidate for CSCSJS or a Mocha Fetchlet
|
|
> A (Re)-Introduction to JavaScript
|
|
> coComment Roundup
|
|
> Track your comments
|
|
> Sketching image queries and reinventing email
|
|
> ECMAScript - The Switzerland of development environments
|
|
> I love E4X
|
|
> Tutorial D, Industrial D and the relational model
|
|
> Stop bashing Java
|
|
> E4X Mocha Objects
|
|
> Logging and other antimatters
|
|
> Stronger types in Javascript 2
|
|
> Javascript Diagnosis & Testing
|
|
> Homo Oxymora
|
|
> Yeah, why not Javascript?
|
|
> Moving beyond Java
|
|
> Spidermonkey Javascript 1.5 finally final
|
|
> Helma Trivia
|
|
> Finding Java Packages
|
|
> JSEclipse Javascript plug-in for Eclipse
|
|
> Catching up to Continuations
|
|
> Mighty and Beastie Licenses
|
|
> Tasting the OpenMocha Console
|
|
> "Who am I?", asks Helma
|
|
> Savety vs Freedom and other recent ramblings
|
|
> Mont-Soleil Open Air Lineup
|
|
> Rhinola - Mocha reduced to the minimum
|
|
> OpenMocha 0.6 available for download
|
|
> E4X presentation by Brendan Eich
|
|
> What is Mocha?
|
|
> Do you remember Gopher?
|
|
> The current.tv disappointment
|
|
> OpenMocha Project Roadmap
|
|
> MochiKit Javascript Library
|
|
> Getting your feet wet with OpenMocha
|
|
> People flocking to see global warming
|
|
> Rails vs Struts vs Mocha
|
|
> The JavaScript Manifesto
|
|
> OpenMocha is ready for a spin
|
|
> The limits of harmonization
|
|
> Le Conseil fédéral au Mont-Soleil
|
|
> Amiga History Guide
|
|
> The people must lead the executive, control the legislature and be the military
|
|
> Copyback License
|
|
> Looking at FreeBSD 6 and Beyond
|
|
> Qualified Minority Veto
|
|
> The Doom of Representative Democracy
|
|
> Violence in a real democracy
|
|
> Concordance and Subsidiarity
|
|
> Wrapping Aspects around Mocha Objects?
|
|
> Future of Javascript Roadmap
|
|
> Baby steps towards Javascript heaven
|
|
> Mac OS X spreading like wildfire
|
|
> Trois petits filous à Faoug
|
|
> Jackrabbit JSR 170
|
|
> Rich components for HTML 5
|
|
> More Java Harmony
|
|
> Mac goes Intel
|
|
> Google goes Rumantsch
|
|
> Oxymoronic Swiss-EU relations
|
|
> Rico and Prototype Javascript libraries
|
|
> Paul Klee - An intangible man and artist
|
|
> Incrementalism in the Mozilla roadmap
|
|
> Mocha multi-threading
|
|
> Moving towards OpenMocha
|
|
> Google goes Portal
|
|
> What Bush doesn't get
|
|
> Unique and limited window of opportunity
|
|
> Persisting Client-side Errors to your Server
|
|
> Dive Into Greasemonkey
|
|
> Brown bears knock on Switzerland's door
|
|
> The experience to make what people want
|
|
> "Just" use HTTP
|
|
> Yes, what is gather?
|
|
> A Free Song for Every Swiss Citizen
|
|
> Java in Harmony
|
|
> Jan getting carried away
|
|
> Evil Google Web Accelerator?
|
|
> JSON.stringify and JSON.parse
|
|
> Ajax for Java
|
|
> The launching of launchd
|
|
> Timeless RSS
|
|
> Kupu
|
|
> SNIFE goes Victorinox
|
|
> AJAX is everywhere
|
|
> Papa Ratzi
|
|
> How Software Patents Work
|
|
> Ten good practices for writing Javascript
|
|
> Free-trade accord with japan edges closer
|
|
> Mocha at a glance
|
|
> Adobe acquires Macromedia
|
|
> Safari 1.3
|
|
> View complexity is usually higher than model complexity
|
|
> Free Trade Neutrality
|
|
> SQL for Java Objects
|
|
> Security Bypass
|
|
> Exactly 1111111111 seconds
|
|
> Kurt goes Chopper
|
|
> Choosing a Java scripting language
|
|
> Spamalot's will get spammed a lot
|
|
> The visual Rhino debugger
|
|
> The Unix wars
|
|
> EU-Council adopts software patent directive
|
|
> FreeBSD baby step "1j"
|
|
> Never trust a man who can count to 1024 on his fingers
|
|
> Visiting the world's smallest city
|
|
> Finally some non-MS, non-nonsense SPF news
|
|
> Swiss cows banned from eating grass
|
|
> Ludivines, the "Green Fairy" of absinthe
|
|
> First Look At Solaris 10
|
|
> EU Commission Declines Patent Debate Restart
|
|
> Alan Kay's wisdom guiding the OpenLaszlo roadmap towards Mocha?
|
|
> 1 Kilo
|
|
> Re: FreeBSD logo design competition
|
|
> Schweizer Sagen
|
|
> Europas Eidgenossen
|
|
> XMLHttpRequest glory
|
|
> Art Nouveau La Chaux-de-Fonds 2005-2006
|
|
> The Beastie Silhouette
|
|
> The Number One Nightmare
|
|
> Safe and Idempotent Methods such as HEAD and TRACE
|
|
> Sorry, you have been verizoned.
|
|
> Daemons and Pixies and Fairies, Oh My!
|
|
> Sentient life forms as MIME-attachments: RFC 1437
|
|
> Web Developer Extension for Firefox
|
|
> Refactoring until nothing is left
|
|
> Brendan, never tired of providing Javascript support
|
|
> Catching XP in just 20 Minutes
|
|
> Designing the Star User Interface
|
|
> Rhino, Mono, IKVM. Or: JavaScript the hard way
|
|
> Re: SCO
|
|
> Judo
|
|
> Convergence on abstraction and on browser-based Console evaluation
|
|
> Today found out that inifinite uptimes are still an oxymoron
|
|
> New aspects of woven apps
|
|
> Original Contribution License (OCL) 1.0
|
|
> Unified SPF: a grand unified theory of MARID
|
|
> BSD is designed. Linux is grown.
|
|
> 5 vor 12 bei 10 vor 10
|
|
> Mocha vs Helma?
|
|
> Schattenwahrheit: Coup d'etat underway against the Cheney Circle?
|
|
> Abschluss Bilaterale II Schweiz-EU
|
|
> From Adam Smith to Open Source
|
|
> Linux - the desktop for the rest of them
|
|
> Big Bang
|
|
> Leaky Hop Objects
|
|
> Return Path Rewriting (RPR) - Mail Forwarding in the Spam Age
|
|
> Microsoft Discloses Huge Number Of Windows Vulnerabilties
|
|
> Steuerungsabgabe statt Steuern
|
|
> Anno 2003: deployZone
|
|
> The war against terror
|
|
> The war against terror (continued)
|
|
> The relativity of Apple's market share
|
|
> Are humans animals?
|
|
> Anno 1999: Der Oberhasler
|
|
> Anno 1998: crossnet
|
|
> Geschwindigkeit vs Umdrehungszahl
|
|
> Anno 1997: Xmedia
|
|
> "The meaning of life is to improve the quality of all life"
|
|
> Anno 1996: CZV
|
|
> How do I set a DEFAULT HTML-DOCUMENT?
|
|
> Global Screen Design Services
|