Mozilla Rhino CommonJS module support

Friday, September 30, 2011 Posted by Ruslan Matveev 0 comments
Good news, last version of Mozilla Rhino (1.7R3) introduces a fully compliant CommonJS module implementation, and in this blog post I'm going to give you a brief introduction on how to use it in your projects. Okay, so how do we normally manage dependencies in the JavaScript code that is running under Mozilla Rhino? Normally when you want to include the contents of another JavaScript file (for example some library), you call load() function (provided by Rhino shell) and pass the name of the file that you want to include as an argument:

// include XSLTProcessor library
load('XLSTProcessor.js');
// use XSLTProcessor class
var xsltProcessor = new XSLTProcessor('test.xsl');

JavaScript interface for Saxon XSLT processor and Mozilla Rhino

Monday, September 12, 2011 Posted by Ruslan Matveev 1 comments
In one of my previous posts, I've explained how to set up Apache Ant and Mozilla Rhino in order to create platform independent JavaScript environment. I've also mentioned that you can extend JavaScript by accessing Java packages and classes. Last time I showed you how to make use of java.io.File class in order to retrieve list of the files in the specific directory, this very simple example might have made you think about what else can you do with it? So today I'm going to focus a little bit more on this essential part of Mozilla Rhino JavaScript engine, by showing you how to perform XSLT transformation using Saxon XSLT processor.

Managing dependencies with RequireJS

Tuesday, September 6, 2011 Posted by Ruslan Matveev 3 comments
As web applications becoming more and more mature, they inherit more and more techniques and patterns from their older brothers - desktop applications. One of the things that's been there for a while is dependency management. JavaScript itself doesn't provide such functionality out of the box, so there is no way to include file "b.js" from file "a.js" as you would do that in php or any other server side language. However there are plenty of solutions available, that will help you to organize dependency management in your JavaScript code. Today I'm gonna give you an introduction into managing dependencies with RequireJS.

To bind or not to bind, that is in Function.prototype

Friday, September 2, 2011 Posted by Ruslan Matveev 3 comments
Do you know anything about Function.prototype.bind? If you don't then you can get yourself familiar with it by reading this article on MDN. It's pretty hard to guess what it's used for, because the description is very complicated (at least for me) if you try to follow it:

Creates a new function that, when called, itself calls this function in the context of the provided this value, with a given sequence of arguments preceding any provided when the new function was called.