Javascript: Week 2 Recap

0 views
Skip to first unread message

John Trupiano

unread,
Jun 1, 2009, 8:58:44 PM6/1/09
to bmore-...@googlegroups.com
Hey guys,

Mark Fruhling and I were the only two who showed today, but that didn't stop us from covering some decent ground.

First, we took a closer look at the differences between prototypical and classical inheritance.  From my understanding, the primary difference comes in your ability to add methods to an entire class of objects even after they've instances of that class have already been created.  The following example demonstrates this point.

// Create 2 strings
var a = new String("a");
var b = new String("b");

// Create a function pointer for later use
var fn_pointer = function() {
  print("yup, I was called, my str is: " + this);
};

// Give b this function without giving it to a
b.some_function = fn_pointer;

// Demonstrate the a does _not_ have this function
try {
  a.some_function();
}
catch (err) {
  print("function not found: my str is: " + a);
}

// Demonstrate that b _does_ have the function
b.some_function();

// Add the function to all instances of String
String.prototype.some_function = fn_pointer;

// And voila, now a has it
a.some_function();

-----------------------------

After this, we spent a few minutes poking around some of the hotness that is Bespin (https://bespin.mozilla.com/ ).  It's a web-based code editor implemented in javascript + html5.  Looks pretty awesome.  Mark was particularly interested in the custom built scrollbars, layouts and resizable containers.

Then I moved onto seeking out a method to shell out of out js shells.  I was unable to find a way to do this in spidermonkey, and most of my internet searching turned up people being flamed for asking because "javascript runs on the client, not the server."  I found that Microsoft's JScript has libraries to do this and that in the past there was a Mozilla project called LiveConnect that opened up several of the Java libraries to javascript.  That said, I wasn't able to get very far with either of these.

At last, I stumbled upon EJS (http://www.ejscript.org/ ) or embedded javascript.  It is yet another javascript shell, but this one does give you an API to access the filesystem.  I ran out of time before I could get anything meaninful done with it.

I don't believe I'm going to be able to make next week's meeting as I have to be in PA all day.  Is anyone willing to step up and get us steered in a proper direction early for next week so that a reasonable crowd can gather?

-John

Dave Troy

unread,
Jun 2, 2009, 10:17:08 AM6/2/09
to BMore Hackers
Good stuff, John!

I wish I could be there for this but the scheduling is not in the
cards right now.

I thoroughly enjoyed reading Crockford's Javascript: The Good Parts,
as well as his talk at Google. I think the concepts surrounding
private methods and properties are particularly interesting, as well
as the 'method' method he devised. Also memoization and other tricks
he introduced were pretty interesting.

The discussion surrounding the limitations of classical notation and
inheritance was also quite interesting; I like how he showed that
taking advantage of prototypal models and object inheritance could be
more expressive than trying to deal with a strict classical model, and
that true classical models were at least in part an artifact of static
typing.

One thing that Crockford doesn't really touch on, however, but that I
was talking about with my friend Jay Phillips (@jicksta) is that
because JS is not a statically typed language, you really kinda need
unit testing and to adopt a TDD mindset, which I think we all agree on
but haven't necessarily done much in practice.

I am aware of ScrewUnit and some unit testing approaches associated
with Prototype and Scriptaculous, but if there was one thing I wish
Crockford had discussed in some detail, it would be unit testing (and
whatever other flavors of testing make sense as well).

Anyway, my $0.02 -- if you guys end up digging into unit testing in JS
some, I'd love to hear more about it!

Cheers,
Dave
> Bespin (https://bespin.mozilla.com/).  It's a web-based code editor
> implemented in javascript + html5.  Looks pretty awesome.  Mark was
> particularly interested in the custom built scrollbars, layouts and
> resizable containers.
>
> Then I moved onto seeking out a method to shell out of out js shells.  I was
> unable to find a way to do this in spidermonkey, and most of my internet
> searching turned up people being flamed for asking because "javascript runs
> on the client, not the server."  I found that Microsoft's JScript has
> libraries to do this and that in the past there was a Mozilla project called
> LiveConnect that opened up several of the Java libraries to javascript.
> That said, I wasn't able to get very far with either of these.
>
> At last, I stumbled upon EJS (http://www.ejscript.org/) or embedded

Josh Suereth

unread,
Jun 2, 2009, 10:31:59 AM6/2/09
to bmore-...@googlegroups.com
I've actually used JsUnit in combination with the maven-javascript-tools (alpha), but there are still some negatives here.  The biggest is that it uses the XULrunner from Mozilla to start up Firefox, load a page and run the unit tests inside the firefox engine.  You had a lot of power, but the amount of time it took to run unit tests really made them less feasible as "unit" tests and more "integration" tests.

Anyway, I love the JS Language, looking forward to reading the results of your investigations.  I've un?-fortunately been promoted and have no feasible real free time on mondays.

-Josh
Reply all
Reply to author
Forward
0 new messages