Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Proposed extension to the "exports" mechanism in Modules/1.1
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Christian  
View profile  
 More options Oct 21 2011, 1:19 pm
From: Mark Christian <ma...@twitter.com>
Date: Fri, 21 Oct 2011 10:19:25 -0700 (PDT)
Local: Fri, Oct 21 2011 1:19 pm
Subject: Proposed extension to the "exports" mechanism in Modules/1.1
Summary:
We propose a backwards-compatible extension to the exports mechanism
of
Modules/1.1 that will make it easier to export individual pre-made
objects.

Background:
The system we are building occasionally contains individual objects
that
we wish to export. With the current system, exporting them is somewhat
ungainly.

  For example, imagine that we were exporting a router for a dynamic
application:

//  Example module "routes"
  var userPage = require('pages/user'), Router =
  require('classes/router');
  var router = new Router();
  router.route("/:username", userPage.profile);
router.route("/:username/friends", userPage.friends);
//  ...and so on.

exports.instance = router;

All we really want to export here is the router itself, but the
current
system requires us to return it as a property of the exports object.
That means that consuming code has to do something like this:

var router = require('router').instance;

We believe that the consuming code would be more readable if the
.instance was not required:

var router = require('router'); // this is not how it works :(

Proposal:
Rather than having exports be a plain object, have it be a function
that
may or may not be called. If it is called, the first argument is to be
used as the exported value of the function. Otherwise, it is treated
as
a object, just as it currently is.

For example, our router example above currently exports the router
like
this:

exports.instance = router;

We propose an extension to the exports mechanism that would optionally
allow modules to do this instead:

exports(router);

Take the following imaginary implementation of Modules/1.1. Assume
that
"module" is a reference to a Module, and that we track the exports of
all of the modules in the exportsByModule object.

var exports = {};
module(exports);
exportsByModule[module.id] = exports;

This proposed change would change that implementation to something
along
these lines:

var exports = function(obj) {
  // exports called as a function; use first argument as exports for
  // this module
  exportsByModule[module.id] = obj;

}

module(exports);

if (typeof(exportsByModule[module.id]) == 'undefined') {
  // traditional behavior; copy properties that were added to exports
  exportsByModule[module.id] = {};
  for(var key in exports) {
    if(exports.hasOwnProperty(key)) {
      exportsByModule[module.id][key] = exports[key];
    }
  }

}

We believe that this change is useful and makes certain use cases more
readable, while remaining fully backwards compatible with Modules/1.1.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wes Garland  
View profile  
 More options Oct 23 2011, 7:51 pm
From: Wes Garland <w...@page.ca>
Date: Sun, 23 Oct 2011 19:51:57 -0400
Local: Sun, Oct 23 2011 7:51 pm
Subject: Re: [CommonJS] Proposed extension to the "exports" mechanism in Modules/1.1

Mark;

Without commenting specifically on this proposal, have you seen the "return
exports" and "setExports" proposals?

Wes

--
Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan Stott  
View profile  
 More options Oct 24 2011, 10:47 am
From: Nathan Stott <nrst...@gmail.com>
Date: Mon, 24 Oct 2011 09:47:07 -0500
Local: Mon, Oct 24 2011 10:47 am
Subject: Re: [CommonJS] Proposed extension to the "exports" mechanism in Modules/1.1

Also Node's module.exports


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »