The Artima Developer Community
Sponsored Link

PHP Buzz Forum
javascript2, ECMAScript4 and dmdscript.

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Alan Knowles

Posts: 390
Nickname: alank
Registered: Sep, 2004

Alan Knowles is Freelance Developer, works on PHP extensions and PEAR.
javascript2, ECMAScript4 and dmdscript. Posted: Jul 27, 2007 2:32 AM
Reply to this message Reply

This post originated from an RSS feed registered with PHP Buzz by Alan Knowles.
Original Post: javascript2, ECMAScript4 and dmdscript.
Feed Title: Smoking toooo much PHP
Feed URL: http://www.akbkhome.com/blog.php/RSS.xml
Feed Description: More than just a blog :)
Latest PHP Buzz Posts
Latest PHP Buzz Posts by Alan Knowles
Latest Posts From Smoking toooo much PHP

Advertisement
Last week I had a go using my little bindings for something useful, rather than just being a little toy. One of the projects I was working on was a hack to exim4, that logged all incomming and outgoing attachments into mysql and stored them on the filesystem.

The basic idea was that the company needed the ability to review if any sensitive data was being sent out by email. The exim hacks are pretty simple for this (hook into the mime handler). The web viewer uses extjs and PHP at the backend, it's a small addition to their current email management interface.

But one area that was needed was a little cron job that cleaned up the directories and deleted data and files older than 2 weeks (so they dont get too clogged up.)

I thought this would be an interesting test of the mysql and file system bindings. So I threw together a horrifically simplistic version of DataObjects, and a short script that did an SQL query and based on the results deleted records and files.

One issue was that I could not really do the DataObjects thing of overlaying the results, or query options into the dataobject as object variables in javascript are overlaid into the same namespaces as methods, so you could accidentally delete methods if your database had matching names. - So the data just gets put in (dataobject).data.* 

The other issue was that the syntax for javascript while fun and flexible could really do with a class construct. If you look through the specifications for ECMAScript4, There is a huge amount of changes making Javascript as we know it far more Java / PHP5'y.. with interfaces, public private etc. So I had a go at adding some of the new features into the dmdscript core.

I've managed to get class's and include working. although it probably needs quite a bit more testing. This basic syntax now works
include "mytest.ds"; // this is run at compile time (not runtime!)

class A {
function A() {
println("This is the constructor A");

}
var c = 12;
function B() {
println("This is B and c is " + this.c);
}


}
class C extends A
{
function C() {
println("This is the constructor C");
A.prototype.constructor.call(this);
}
function D() {
println("This is D and c is " + this.c);
}
}


var a = new A();
a.B();

var c = new C();
c.B();
c.D();

Will successfully output

Hello from mytest
This is the constructor A
This is B and c is 12
This is the constructor C
This is the constructor A
This is B and c is 12
This is D and c is 12

Now I can start writing tidy little javascript libraries...




Read: javascript2, ECMAScript4 and dmdscript.

Topic: OSCON 2007: Days 3 and 4 Previous Topic   Next Topic Topic:

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use