Skip to content

Instantly share code, notes, and snippets.

James Halliday substack

Block or report user

Report or block substack

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
domenic /
Last active Jun 12, 2019
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

paulirish / XHR2.js
Created Dec 4, 2011
detects for testling
View XHR2.js
trying out some XHR2 detects for
testling is awwwesome.
curl -u xxx@xxx \
-sSNT XHR2.js ',iexplore/7.0,iexplore/8.0,iexplore/9.0,chrome/4.0,chrome/5.0,chrome/6.0,chrome/7.0,chrome/8.0,chrome/9.0,chrome/10.0,chrome/11.0,chrome/12.0,chrome/13.0,chrome/14.0,chrome/15.0,firefox/4.0,firefox/5.0,firefox/6.0,firefox/7.0,firefox/8.0,opera/10.0,opera/10.5,opera/11.0,opera/11.5,safari/5.0.5,safari/5.1,firefox/nightly,opera/next,chrome/canary'
var test = require('testling');
View twitter.js
var tweasy = require("tweasy")
OAuth = require("oauth").OAuth,
inspect = require('eyes').inspector({
maxLength: 16384
var oauthConsumer = new OAuth(
"", // can't remember what this is
View Object.defineProperty
node> o = { foo : 'bar' }
{ foo: 'bar' }
node> Object.defineProperty(o, 'moo', { value : 'cows', enumerable: false })
{ foo: 'bar' }
node> Object.keys(o)
[ 'foo' ]
node> o.moo
node> Object.getOwnPropertyDescriptor(o, 'moo')
You can’t perform that action at this time.