Question

I'm moving a solution from .Net 2 to 4.5 and upgrading to Script# 0.8.

The release notes for Script# 0.8 say:

GlobalMethodsAttribute is gone (no implicit generation of methods on to the global script object, you must instead do it explicitly by assigning a delegate to the member on the global object)

How do you reference the 'global object'? for most of the projects I was able to work around this, but I have a couple where every other method is tagged with:

[Global]

UPDATE

I found this in my AssemblyInfo.cs

[assembly: ScriptTemplate(@"
/*! {name}.js {version}
 * {description}
 */

""use strict"";

require([{requires}], function({dependencies}) {
  var $global = this;
  {script}
});

")]

Anything I specify here gets inserted into the compiled javascript - is this the place to define globals?

Was it helpful?

Solution

To set something on the global object, use Script.SetField using Script.Global as the instance object. Writing from memory, but do believe those are the API of interest.

You can update the script template if you want to add some directly authored JavaScript instead of generated script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top