---
title: First class dependency objects in ECMAScript Harmony
description: How to use first class dependency objects with ECMAScript Harmony.
---

[Blog ](https://www.metaltoad.com/blog)

# [First class dependency objects in ECMAScript Harmony](https://www.metaltoad.com/blog/first-class-dependency-objects-ecmascript-harmony)

 Written by [Metal Toad Staff](https://www.metaltoad.com/blog/author/metal-toad-staff) | Feb 21, 2012 12:00:00 AM

 Filed under:

- [Javascript](https://www.metaltoad.com/help/javascript)

My favorite perk of [Require.JS](http://requirejs.org) is how dependencies are sent as arguments to a factory function. Treating dependencies as first class objects makes much more sense to me than polluting the window object - something that happens too much with other dependency management solutions (I'm looking at you, [Steal.JS](http://javascriptmvc.com/docs.html#!stealjs)).

I was curious how I might get this functionality with the next generation of JavaScript - namely, [ECMAScript Harmony](http://wiki.ecmascript.org/doku.php?id=harmony:modules). No browsers implement Harmony's module system just yet, so pardon the pseudocode.

### First class dependency objects via Require.JS

 define([   
 '../src/helloworld',   
 '../lib/jquery',   
 ],   
 function(helloworld, $){   
 $('body').html(helloworld.sayIt());   
 });

In this example, `helloworld.js` and `jquery.js` are fully loaded first, then passed as objects named `helloworld` and `$`, respectively. Once in the factory function, I have free reign over the dependencies' methods, properties, and prototypes.

### First class dependency objects via ECMAScript Harmony

 module helloworld from '../src/helloworld.js';   
 module $ from '../lib/jquery.js';   
 $('body').html(helloworld.sayIt());

This is the same result as Require.JS - the dependencies are loaded asynchronously (Harmony loads modules at compile time), and the dependencies are nicely encapsulated in their respective first class objects.

As it stands, I find the Require.JS syntax to be more readable. The list of dependencies and their mapping to objects is crystal clear. Since I haven't been able to test ECMAScript Harmony modules in a browser yet, the jury is still out on the pleasures of the new module syntax.

[View full post](https://www.metaltoad.com/blog/first-class-dependency-objects-ecmascript-harmony)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Metal Toad Staff"
  },
  "dateModified" : "2023-12-06T23:28:07.982Z",
  "datePublished" : "2012-02-21T00:00:00Z",
  "headline" : "First class dependency objects in ECMAScript Harmony",
  "image" : {
    "@type" : "ImageObject",
    "height" : 500,
    "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/Imported_Blog_Media/Metal_Toad_blog_generic-Aug-11-2023-10-22-59-0447-PM.jpg",
    "width" : 870
  },
  "mainEntityOfPage" : "https://www.metaltoad.com/blog/first-class-dependency-objects-ecmascript-harmony",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60.0,
      "url" : "https://6104926.fs1.hubspotusercontent-na1.net/hubfs/6104926/social-suggested-images/6104926.fs1.hubspotusercontent-na1.nethub6104926hubfsMetal_Toad_Logo_orange_horizontal-50-1.jpg",
      "width" : 240.00002
    },
    "name" : "Blog"
  }
}
```