prototypejs / prototype

Prototype JavaScript framework
http://prototypejs.org/
Other
3.54k stars 639 forks source link

Load JS in a Context #303

Closed tkellehe closed 8 years ago

tkellehe commented 8 years ago

Hello, I had written my own AJAX function when learning about how ajax requests work. Obviously, it did not have all of the amazing features that prototypeJS Ajax provides. So, I have been using this one for a decent amount of my projects. There was a component that I enjoyed from the one I wrote that allowed me to load js into a particular context. This allowed me to write libraries that when loaded would attach to the scope they were ran in, making it very useful when using third party libraries. Would it be possible to add an option such that when using evalJS = true I can provide another option to eval the js in?

    var context = {...};
    new Ajax.Request({evalJS:true, evalContext:context});
    // or
    new Ajax.Request({evalJS:context});

The js I used to accomplish this followed along the lines of:

    var result = function(code) {
         return eval(code);
    }.call(context, code);