Expose moment in Demandware environment #1034

Closed
intel352 opened this Issue Aug 29, 2013 · 7 comments

Projects

None yet

4 participants

@intel352

I'm working on a site built using Demandware (hosted ecommerce platform). Demandware is built on Java, and has Rhino included for scripting. ES4th edition proposal is supported with JS 1.7, but there seem to be limitations/bugs in some of the native ES functionality. Scripts are given the extension .ds, variables are not exported (only functions).

To get Moment working within Demandware, I renamed the file to Moment.ds, and added the following to the top of the file:

// Function to make Moment available
var moment;
function getMoment() {
    return moment;
}

Then in any script that includes Moment.ds, I have to add var moment = getMoment();.

If you could add this information somewhere, or somehow use it to further expose Moment for closed environments such as Demandware, that would be excellent.

@icambron
Member

Huh. I've never heard of Demandware, but I guess I don't understand the issue exactly. Why can Moment.ds find moment, but other files can't?

@chall8908
Contributor

I've run into references to this particular platform before, I think. The issue is that, to Demandware, moment is a variable, not a function, and only "global" functions are visible outside a particular file.

Though, I'm a little curious why Demandware can't tell that a variable assigned a function ( var foo = function() {}) and a variable created as a function (function foo() {}) are (mostly) the same thing.

@icambron
Member
icambron commented Oct 4, 2013

I linked to this issue from the docs: http://momentjs.com/docs/#/use-it/other/

@icambron icambron closed this Oct 4, 2013
@kumarharsh

docs? what docs? localhost?

@icambron
Member

Sorry, edited

@kumarharsh

sorry... on second reading, i sounded like an idiot :(
no offence intended.

This is the first time outside of a company of a friend of mine that I'm even hearing the name of demandware though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment