new Function([arg1[, arg2[, ... argN]], ] functionBody) like in JavaScript ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

new Function([arg1[, arg2[, ... argN]], ] functionBody) like in JavaScript ?

Joe List
Hello all,

I'm new to haxe. Is it possible to create function in haxe like in JavaScript:
var twoNumAverage = new Function("x", "y", "return (x + y)/2")
document.write(twoNumAverage(3,7)) // result 5

Saw here:
http://www.devguru.com/technologies/ecmascript/quickref/function_object.html


I know it's impossible in as3.
Colin moock book:
"The Function constructor : ActionScript does not support the Function constructor, which is used in JavaScript to create functions with the syntax new Function ( );."

Saw here:
http://docstore.mik.ua/orelly/web2/action/appd_01.htm

But perhaps with the magic of haxe is it possible to generate?


My idea is to make perhaps similar thing for flash than the underscore.js template system:

var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
_.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"

http://documentcloud.github.com/underscore/#template
https://github.com/documentcloud/underscore/blob/master/underscore.js#L747

Thanks

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: new Function([arg1[, arg2[, ... argN]], ] functionBody) like in JavaScript ?

Cauê W.
you can have a look at hscript

It will allow you to create haXe expressions with strings and run them at runtime. It will be much slower, though, as it will interpret the code at runtime.

Cheers!
Cauê

2011/6/24 Joe List <[hidden email]>
Hello all,

I'm new to haxe. Is it possible to create function in haxe like in JavaScript:
var twoNumAverage = new Function("x", "y", "return (x + y)/2")
document.write(twoNumAverage(3,7)) // result 5

Saw here:
http://www.devguru.com/technologies/ecmascript/quickref/function_object.html


I know it's impossible in as3.
Colin moock book:
"The Function constructor : ActionScript does not support the Function constructor, which is used in JavaScript to create functions with the syntax new Function ( );."

Saw here:
http://docstore.mik.ua/orelly/web2/action/appd_01.htm

But perhaps with the magic of haxe is it possible to generate?


My idea is to make perhaps similar thing for flash than the underscore.js template system:

var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
_.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"

http://documentcloud.github.com/underscore/#template
https://github.com/documentcloud/underscore/blob/master/underscore.js#L747

Thanks

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: new Function([arg1[, arg2[, ... argN]], ] functionBody) like in JavaScript ?

Joe List
Wow hscript.
Thanks for the help Cauê.

2011/6/24 Cauê Waneck <[hidden email]>
you can have a look at hscript

It will allow you to create haXe expressions with strings and run them at runtime. It will be much slower, though, as it will interpret the code at runtime.

Cheers!
Cauê

2011/6/24 Joe List <[hidden email]>
Hello all,

I'm new to haxe. Is it possible to create function in haxe like in JavaScript:
var twoNumAverage = new Function("x", "y", "return (x + y)/2")
document.write(twoNumAverage(3,7)) // result 5

Saw here:
http://www.devguru.com/technologies/ecmascript/quickref/function_object.html


I know it's impossible in as3.
Colin moock book:
"The Function constructor : ActionScript does not support the Function constructor, which is used in JavaScript to create functions with the syntax new Function ( );."

Saw here:
http://docstore.mik.ua/orelly/web2/action/appd_01.htm

But perhaps with the magic of haxe is it possible to generate?


My idea is to make perhaps similar thing for flash than the underscore.js template system:

var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
_.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"

http://documentcloud.github.com/underscore/#template
https://github.com/documentcloud/underscore/blob/master/underscore.js#L747

Thanks

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: new Function([arg1[, arg2[, ... argN]], ] functionBody) like in JavaScript ?

Tony Polinelli
If you are looking for templating languages there are a few existing projects: 

haxe.template - is the most basic

erazor - uses hscript for most of the syntax i think:




On Sat, Jun 25, 2011 at 6:14 AM, Joe List <[hidden email]> wrote:
Wow hscript.
Thanks for the help Cauê.


2011/6/24 Cauê Waneck <[hidden email]>
you can have a look at hscript

It will allow you to create haXe expressions with strings and run them at runtime. It will be much slower, though, as it will interpret the code at runtime.

Cheers!
Cauê

2011/6/24 Joe List <[hidden email]>
Hello all,

I'm new to haxe. Is it possible to create function in haxe like in JavaScript:
var twoNumAverage = new Function("x", "y", "return (x + y)/2")
document.write(twoNumAverage(3,7)) // result 5

Saw here:
http://www.devguru.com/technologies/ecmascript/quickref/function_object.html


I know it's impossible in as3.
Colin moock book:
"The Function constructor : ActionScript does not support the Function constructor, which is used in JavaScript to create functions with the syntax new Function ( );."

Saw here:
http://docstore.mik.ua/orelly/web2/action/appd_01.htm

But perhaps with the magic of haxe is it possible to generate?


My idea is to make perhaps similar thing for flash than the underscore.js template system:

var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
_.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"

http://documentcloud.github.com/underscore/#template
https://github.com/documentcloud/underscore/blob/master/underscore.js#L747

Thanks

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org