FAQ
Actually, it's a Go sub-set, but it's just enough to use it instead of JS
or another translator like CoffeScript.
I wanted to free this version now since somebody could be interested in
build libraries or applications in Go for JS.

Now, it lacks the handle of function types, interfaces (I hope I can
translate them), goroutines and defer (they're possible), channels (I think
that I can, at least I've the idea), type switches (working on it), complex
numbers (handled in closed repo.), and integers of 64 bits (it's possible
using a type to handle them using 2 integers of 32 bits).

The library that handles Go types and its features is in:
https://github.com/kless/go2js/tree/master/jslib
And the tests used are in
https://github.com/kless/go2js/tree/master/testdata
To check fastly that the translation is right, I load all JS test files
generated using "go test -v" in the browser using the file:
https://github.com/kless/go2js/blob/master/testdata/test.html

Into a translator like this one, It's very important the use of a great
amount of tests to match different possibilities but it's possible that
I've not mathched any possibility. If you find that the translation of your
program faills in JS, please, fill in an issue with the code where the
translation is incorrect. Note that I know that some function related to
methods is not correctly translated (and will be fixed, of course).

Important: wether somebody is going to contribute in something, please only
touch the Go tests files (in tesdata), or the library "jslib.go" if you
think that you can get a better algo. to handle slices or arrays, or to
handle the integers of 64 bits.

https://github.com/kless/go2js


Note: the full version is being developed into a closed repository, because
the code will be free/open only when I finish of coding another tools
related to it. When Go2js is finished, I'll add binaries for main platforms
so it will can be used while the source code remains closed.
I'm not going to ask money for the full version; my business model is not
there.

--

Search Discussions

  • Egon at Nov 17, 2012 at 2:05 am
    For defer you can probably do something like:

    func (){
    ...A...
    defer func(val thing){
    if err := recover(); err != nil {
    ...F...
    }
    }(arg)
    ...B...
    }

    function(){
    ...A...

    var $defer0 = function(panic){
    var recover = function(){
    var temp = panic; panic = null; return temp;
    };
    (function(val){
    if err = recover(), err != null {
    ...F...
    }
    })(arg);

    if(panic != null)
    throw(panic)
    };

    try {
    ...B...
    } catch( panic ) {
    $defer0(panic);
    } finally {
    $defer0(null);
    }
    }

    + egon
    On Saturday, November 17, 2012 1:53:27 AM UTC+2, Archos wrote:

    Actually, it's a Go sub-set, but it's just enough to use it instead of JS
    or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    --
  • Archos at Nov 17, 2012 at 10:05 am
    I've a branch where I'd started to handle defers, and it works with defers
    of anonymous functions, by now.
    I use an array like a stack which is called after of the function.

    I use it of this way because my main goal on this project was, and it
    follows being, to do a translating line-to-line which is very useful at
    time of debugging.

    Important: I had forgotten to say that I've no checked the translation of
    nested maps or types. That will be the last part when all sintaxis been
    correctly translated.

    El sábado, 17 de noviembre de 2012 02:05:43 UTC, egon escribió:
    For defer you can probably do something like:

    func (){
    ...A...
    defer func(val thing){
    if err := recover(); err != nil {
    ...F...
    }
    }(arg)
    ...B...
    }

    function(){
    ...A...

    var $defer0 = function(panic){
    var recover = function(){
    var temp = panic; panic = null; return temp;
    };
    (function(val){
    if err = recover(), err != null {
    ...F...
    }
    })(arg);

    if(panic != null)
    throw(panic)
    };

    try {
    ...B...
    } catch( panic ) {
    $defer0(panic);
    } finally {
    $defer0(null);
    }
    }

    + egon
    On Saturday, November 17, 2012 1:53:27 AM UTC+2, Archos wrote:

    Actually, it's a Go sub-set, but it's just enough to use it instead of JS
    or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    --
  • Egon at Nov 18, 2012 at 12:46 am
    Yeah it's actually probably a simpler approach, my version totally fails if
    defer is called inside an `if`.
    On Saturday, November 17, 2012 12:05:50 PM UTC+2, Archos wrote:

    I've a branch where I'd started to handle defers, and it works with defers
    of anonymous functions, by now.
    I use an array like a stack which is called after of the function.

    I use it of this way because my main goal on this project was, and it
    follows being, to do a translating line-to-line which is very useful at
    time of debugging.

    Important: I had forgotten to say that I've no checked the translation of
    nested maps or types. That will be the last part when all sintaxis been
    correctly translated.

    El sábado, 17 de noviembre de 2012 02:05:43 UTC, egon escribió:
    For defer you can probably do something like:

    func (){
    ...A...
    defer func(val thing){
    if err := recover(); err != nil {
    ...F...
    }
    }(arg)
    ...B...
    }

    function(){
    ...A...

    var $defer0 = function(panic){
    var recover = function(){
    var temp = panic; panic = null; return temp;
    };
    (function(val){
    if err = recover(), err != null {
    ...F...
    }
    })(arg);

    if(panic != null)
    throw(panic)
    };

    try {
    ...B...
    } catch( panic ) {
    $defer0(panic);
    } finally {
    $defer0(null);
    }
    }

    + egon
    On Saturday, November 17, 2012 1:53:27 AM UTC+2, Archos wrote:

    Actually, it's a Go sub-set, but it's just enough to use it instead of
    JS or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is
    not there.
    --
  • Archos at Nov 19, 2012 at 10:04 am
    Do you think that it's really useful to can translate the type
    assertions[1] and type switches[2] from Go to JS? Could say a real example
    where it could be necessary in JS?

    The issue is that for translate it, there is to add a type signature to
    custom types to be used in JS which is complicating much everything. i.e.

    + before, to define a boolean (after of be translated to JS): var a = true;
    after, with initial change to allow those features: var a = g.Bool(true);
    // G.Bool sets the signature of the type

    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the zero
    value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5, "Go":
    4.5} // add the signature for this map


    [1]: http://golang.org/ref/spec#Type_assertions
    [2]: http://golang.org/ref/spec#Switch_statements

    --
  • Ross Light at Nov 19, 2012 at 4:43 pm
    My two cents, I've been glancing at this project for a while.
    On Mon, Nov 19, 2012 at 2:04 AM, Archos wrote:

    Do you think that it's really useful to can translate the type assertions[1] and type switches[2] from Go to JS? Could say a real example where it could be necessary in JS?
    It's not necessarily useful in JS, but the use I see in converting
    from Go to Javascript is having the static type-checking. If you
    didn't implement this, there's no way to convert between types.
    The issue is that for translate it, there is to add a type signature to custom types to be used in JS which is complicating much everything. i.e.
    No, you keep the type information in the translator until you need to
    convert to an interface, then you put runtime type info on it. Same
    as how the other implementations do it.
    + before, to define a boolean (after of be translated to JS): var a = true;
    after, with initial change to allow those features: var a = g.Bool(true); // G.Bool sets the signature of the type

    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the zero value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5, "Go": 4.5} // add the signature for this map


    [1]: http://golang.org/ref/spec#Type_assertions
    [2]: http://golang.org/ref/spec#Switch_statements

    --
    Line-by-line translation will only get you so far; for more complex
    features, you will need to build up a more sophisticated data
    structure.

    --
  • Archos at Nov 19, 2012 at 8:58 pm
    El lunes, 19 de noviembre de 2012 16:44:10 UTC, Ross Light escribió:
    My two cents, I've been glancing at this project for a while.

    On Mon, Nov 19, 2012 at 2:04 AM, Archos <raul...@sent.com <javascript:>>
    wrote:
    Do you think that it's really useful to can translate the type
    assertions[1] and type switches[2] from Go to JS? Could say a real example
    where it could be necessary in JS?

    It's not necessarily useful in JS, but the use I see in converting
    from Go to Javascript is having the static type-checking. If you
    didn't implement this, there's no way to convert between types.
    In addition of having the static type-checking, there are another
    advantages like

    + to use one only language for all project (I dislike JS; and in fact, this
    is the first time that I've learnt)
    + the use of a language well designed (JS handles all number like floats,
    shadow variables, it's hard to debug, ...)

    Wether JS is widely used, is simply because it is the only choice to use in
    browsers.
    The issue is that for translate it, there is to add a type signature to
    custom types to be used in JS which is complicating much everything. i.e.

    No, you keep the type information in the translator until you need to
    convert to an interface, then you put runtime type info on it. Same
    as how the other implementations do it.
    There is only 2 options; one is to save the type information for every
    variable into a map global, for then access to in case of access to the
    type. And the another one, (the path I've followed), is to create a type
    (function in JS) for each Go type which has a field named _type, i.e. for
    bool:

    type BoolType struct {
    _type int // type
    _val interface{} // value
    }

    The bad side, is that every value (included values in arraies, maps and
    slices) handled in JS has to be created using those functions. The good
    side is that I get easily the type and the translation of the type switch
    is so simple (using the field "_type").
    + before, to define a boolean (after of be translated to JS): var a =
    true;
    after, with initial change to allow those features: var a =
    g.Bool(true); // G.Bool sets the signature of the type
    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the
    zero value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5,
    "Go": 4.5} // add the signature for this map

    [1]: http://golang.org/ref/spec#Type_assertions
    [2]: http://golang.org/ref/spec#Switch_statements

    --
    Line-by-line translation will only get you so far; for more complex
    features, you will need to build up a more sophisticated data
    structure.
    --
  • Egon at Nov 20, 2012 at 1:48 am

    On Monday, November 19, 2012 12:04:24 PM UTC+2, Archos wrote:

    Do you think that it's really useful to can translate the type
    assertions[1] and type switches[2] from Go to JS? Could say a real example
    where it could be necessary in JS?

    The issue is that for translate it, there is to add a type signature to
    custom types to be used in JS which is complicating much everything. i.e.
    Yes it would be nice to have type-assertions at runtime.

    You probably can just do something like https://gist.github.com/4115360.

    Essentially to each function attach a type signature. Now since each struct
    will have a constructor function, you can use that as a type. You also may
    want to attach some fully qualified names to constructors to avoid
    mistaking two constructors with the same name. Then you can just implement
    an Interface that contains only function signatures and a cache for things
    that it already has fully checked.

    + before, to define a boolean (after of be translated to JS): var a = true;
    after, with initial change to allow those features: var a =
    g.Bool(true); // G.Bool sets the signature of the type
    Not needed, since you can ask for the "a.constructor" which gives you
    "Boolean".

    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the
    zero value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5, "Go":
    4.5} // add the signature for this map
    For maps, arrays and slices you probably need special handling.
  • Archos at Nov 20, 2012 at 11:24 am
    El martes, 20 de noviembre de 2012 01:40:13 UTC, egon escribió:
    On Monday, November 19, 2012 12:04:24 PM UTC+2, Archos wrote:

    Do you think that it's really useful to can translate the type
    assertions[1] and type switches[2] from Go to JS? Could say a real example
    where it could be necessary in JS?

    The issue is that for translate it, there is to add a type signature to
    custom types to be used in JS which is complicating much everything. i.e.
    Yes it would be nice to have type-assertions at runtime.
    Ok, then I'll follow on it.

    You probably can just do something like https://gist.github.com/4115360.
    Essentially to each function attach a type signature. Now since each
    struct will have a constructor function, you can use that as a type. You
    also may want to attach some fully qualified names to constructors to avoid
    mistaking two constructors with the same name. Then you can just implement
    an Interface that contains only function signatures and a cache for things
    that it already has fully checked.
    I've implemented of different way, do you have a bitbucket account for if
    want to see how it is implemented?

    + before, to define a boolean (after of be translated to JS): var a =
    true;
    after, with initial change to allow those features: var a =
    g.Bool(true); // G.Bool sets the signature of the type
    Not needed, since you can ask for the "a.constructor" which gives you
    "Boolean".
    Interesting. I didn't know about "constructor.name"; it could be useful for
    me in some point.

    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the
    zero value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5, "Go":
    4.5} // add the signature for this map
    For maps, arrays and slices you probably need special handling.
    Yep, that is really the hard part ;)
    but there is solution

    --
  • Egon at Nov 20, 2012 at 4:03 pm

    On Tuesday, November 20, 2012 1:24:26 PM UTC+2, Archos wrote:

    El martes, 20 de noviembre de 2012 01:40:13 UTC, egon escribió:
    On Monday, November 19, 2012 12:04:24 PM UTC+2, Archos wrote:

    Do you think that it's really useful to can translate the type
    assertions[1] and type switches[2] from Go to JS? Could say a real example
    where it could be necessary in JS?

    The issue is that for translate it, there is to add a type signature to
    custom types to be used in JS which is complicating much everything. i.e.
    Yes it would be nice to have type-assertions at runtime.
    Ok, then I'll follow on it.

    You probably can just do something like https://gist.github.com/4115360.
    Essentially to each function attach a type signature. Now since each
    struct will have a constructor function, you can use that as a type. You
    also may want to attach some fully qualified names to constructors to avoid
    mistaking two constructors with the same name. Then you can just implement
    an Interface that contains only function signatures and a cache for things
    that it already has fully checked.
    I've implemented of different way, do you have a bitbucket account for if
    want to see how it is implemented?
    https://bitbucket.org/egon

    + before, to define a boolean (after of be translated to JS): var a =
    true;
    after, with initial change to allow those features: var a =
    g.Bool(true); // G.Bool sets the signature of the type
    Not needed, since you can ask for the "a.constructor" which gives you
    "Boolean".
    Interesting. I didn't know about "constructor.name"; it could be useful
    for me in some point.
    I suggest using your special uuids instead, since constructors can have
    same name.


    + before, for a map: var m = g.Map(0, {"C": 5, "Go": 4.5}; // 0 is the
    zero value for the map
    after: var m = g.Map("map[string]float32", g.Float32(0), {"C": 5,
    "Go": 4.5} // add the signature for this map
    For maps, arrays and slices you probably need special handling.
    Yep, that is really the hard part ;)
    but there is solution
    --
  • Brian Slesinsky at Nov 19, 2012 at 5:18 pm
    Congratulations on getting this far; this isn't a small project.
    On Friday, November 16, 2012 3:53:27 PM UTC-8, Archos wrote:

    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    Could you clarify your intentions? Do you intend the compiler itself to be
    come an open source project (accepting patches)? Which parts will be closed?

    Context: in my spare time, I've been working on my own Go to JavaScript
    compiler which hasn't gotten as far, though I do handle some things like
    constant expressions. I'd be willing to contribute to another open source
    project instead if it seems reasonable.

    - Brian

    --
  • Archos at Nov 19, 2012 at 8:32 pm
    El lunes, 19 de noviembre de 2012 17:18:46 UTC, Brian Slesinsky escribió:
    Congratulations on getting this far; this isn't a small project.
    Thanks! No, it isn't small, and every time that it's added something new to
    translating is like to solve an reverse puzzle since every new piece add
    more complexity and ease to break actual work.
    On Friday, November 16, 2012 3:53:27 PM UTC-8, Archos wrote:

    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    Could you clarify your intentions? Do you intend the compiler itself to be
    come an open source project (accepting patches)? Which parts will be closed?
    My intentions are to (finish) develop a set of tools related to Go on the
    web --at the same time while I'm developing a web service although they are
    not related except I'm using Go2js--.
    So, by now it remains closed but it will be opern source too like this
    version.

    The parts closed are those that are not translated now in the free version,
    althouh I'll fix issues there too.

    Context: in my spare time, I've been working on my own Go to JavaScript
    compiler which hasn't gotten as far, though I do handle some things like
    constant expressions. I'd be willing to contribute to another open source
    project instead if it seems reasonable.
    Well, if you have a bitbucket account I could give you access to my
    repository.

    --
  • Tomwilde at Nov 20, 2012 at 11:43 am
    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/map.js

    Don't compare against 'undefined' directly, 'window.undefined' can be
    overriden (< ECMAScript rev 5).

    use (typeof myVar === 'undefined') instead.

    Am Samstag, 17. November 2012 00:53:27 UTC+1 schrieb Archos:
    Actually, it's a Go sub-set, but it's just enough to use it instead of JS
    or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    --
  • Archos at Nov 20, 2012 at 11:57 am
    El martes, 20 de noviembre de 2012 11:43:30 UTC, tomwilde escribió:

    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/map.js

    Don't compare against 'undefined' directly, 'window.undefined' can be
    overriden (< ECMAScript rev 5).

    use (typeof myVar === 'undefined') instead.
    But you have in mind that I'm comparing the field "v" of the function Map:

    var m1 = g.Map(0);

    m1.v === undefined


    https://github.com/kless/go2js/blob/master/jslib/lib.js#L469
    https://github.com/kless/go2js/blob/master/jslib/lib.js#L489

    --
  • Tomwilde at Nov 20, 2012 at 12:04 pm
    Doesn't matter what you compare.

    window is the global namespace. Any variable that does not have a define
    scope is a member of window.

    If you set window.undefined to a value, any comparison with just
    'undefined' will refer to the window.undefined value.

    Test this code on IE7:

    window.undefined = 'foo';
    var x = 'foo';
    alert(x === undefined);

    It will yield 'true'.

    Am Dienstag, 20. November 2012 12:57:54 UTC+1 schrieb Archos:

    El martes, 20 de noviembre de 2012 11:43:30 UTC, tomwilde escribió:

    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/map.js

    Don't compare against 'undefined' directly, 'window.undefined' can be
    overriden (< ECMAScript rev 5).

    use (typeof myVar === 'undefined') instead.
    But you have in mind that I'm comparing the field "v" of the function Map:

    var m1 = g.Map(0);

    m1.v === undefined


    https://github.com/kless/go2js/blob/master/jslib/lib.js#L469
    https://github.com/kless/go2js/blob/master/jslib/lib.js#L489
    --
  • Tomwilde at Nov 20, 2012 at 11:57 am
    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/decl_const.js

    There is no 'const' keyword in JS. The concept of a constant does not exist
    in JS.

    What is this?

    Am Samstag, 17. November 2012 00:53:27 UTC+1 schrieb Archos:
    Actually, it's a Go sub-set, but it's just enough to use it instead of JS
    or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    --
  • Archos at Nov 20, 2012 at 11:53 am
    It's a valid statement:

    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/const

    El martes, 20 de noviembre de 2012 11:34:59 UTC, tomwilde escribió:

    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/decl_const.js

    There is no 'const' keyword in JS. The concept of a constant does not
    exist in JS.

    What is this?

    Am Samstag, 17. November 2012 00:53:27 UTC+1 schrieb Archos:
    Actually, it's a Go sub-set, but it's just enough to use it instead of JS
    or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is not
    there.
    --
  • Tomwilde at Nov 20, 2012 at 11:57 am
    It's a proposed keyword for ECMAScript harmony:

    <http://wiki.ecmascript.org/doku.php?id=harmony%3aconst>
    http://stackoverflow.com/questions/2821509/can-you-use-constant-variables-in-javascript

    Focus on generating cross-browser compatible code.

    Am Dienstag, 20. November 2012 12:53:44 UTC+1 schrieb Archos:
    It's a valid statement:


    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/const

    El martes, 20 de noviembre de 2012 11:34:59 UTC, tomwilde escribió:

    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/decl_const.js

    There is no 'const' keyword in JS. The concept of a constant does not
    exist in JS.

    What is this?

    Am Samstag, 17. November 2012 00:53:27 UTC+1 schrieb Archos:
    Actually, it's a Go sub-set, but it's just enough to use it instead of
    JS or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is
    not there.
    --
  • Archos at Nov 20, 2012 at 12:04 pm
    I'l check in more browsers but it's valid for both Firefox and Chromium

    El martes, 20 de noviembre de 2012 11:57:31 UTC, tomwilde escribió:
    It's a proposed keyword for ECMAScript harmony:

    <http://wiki.ecmascript.org/doku.php?id=harmony%3aconst>
    http://stackoverflow.com/questions/2821509/can-you-use-constant-variables-in-javascript

    Focus on generating cross-browser compatible code.

    Am Dienstag, 20. November 2012 12:53:44 UTC+1 schrieb Archos:
    It's a valid statement:


    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/const

    El martes, 20 de noviembre de 2012 11:34:59 UTC, tomwilde escribió:

    https://github.com/kless/go2js/blob/054e62f70d94e926812976147cc66a9bccbc370e/testdata/decl_const.js

    There is no 'const' keyword in JS. The concept of a constant does not
    exist in JS.

    What is this?

    Am Samstag, 17. November 2012 00:53:27 UTC+1 schrieb Archos:
    Actually, it's a Go sub-set, but it's just enough to use it instead of
    JS or another translator like CoffeScript.
    I wanted to free this version now since somebody could be interested in
    build libraries or applications in Go for JS.

    Now, it lacks the handle of function types, interfaces (I hope I can
    translate them), goroutines and defer (they're possible), channels (I think
    that I can, at least I've the idea), type switches (working on it), complex
    numbers (handled in closed repo.), and integers of 64 bits (it's possible
    using a type to handle them using 2 integers of 32 bits).

    The library that handles Go types and its features is in:
    https://github.com/kless/go2js/tree/master/jslib
    And the tests used are in
    https://github.com/kless/go2js/tree/master/testdata
    To check fastly that the translation is right, I load all JS test files
    generated using "go test -v" in the browser using the file:
    https://github.com/kless/go2js/blob/master/testdata/test.html

    Into a translator like this one, It's very important the use of a great
    amount of tests to match different possibilities but it's possible that
    I've not mathched any possibility. If you find that the translation of your
    program faills in JS, please, fill in an issue with the code where the
    translation is incorrect. Note that I know that some function related to
    methods is not correctly translated (and will be fixed, of course).

    Important: wether somebody is going to contribute in something, please
    only touch the Go tests files (in tesdata), or the library "jslib.go" if
    you think that you can get a better algo. to handle slices or arrays, or to
    handle the integers of 64 bits.

    https://github.com/kless/go2js


    Note: the full version is being developed into a closed repository,
    because the code will be free/open only when I finish of coding another
    tools related to it. When Go2js is finished, I'll add binaries for main
    platforms so it will can be used while the source code remains closed.
    I'm not going to ask money for the full version; my business model is
    not there.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 16, '12 at 11:53p
activeNov 20, '12 at 4:03p
posts19
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase