Comments (5)
Could you add an example with an anon. function where it fails?
from go2js.
Currently it doesn't seem to support properly, but here's a simple example:
type test struct {
value string
}
func (t *test) get() func() string {
return func() string {
return t.value
}
}
func main() {
test := &test{"hello"}
fn := test.get()
fmt.Print(fn())
}
The expected output for that get
function should be:
test.prototype.get = function(){
var t = this;
return function(){
return t.value;
}
};
Otherwise when calling fn
in main
it will use the global this
.
from go2js.
+1 on this proposal, although perhaps the aliased name should be underscored prefixed (e.g. "var _this = this;")
from go2js.
Not really, it may make sense using in javascript but in a translator it's better to use the method receiver instead. You need the method receiver anyway so renaming the receiver to "this" in javascript adds nothing useful. Alternative of using the same variable name from the method receiver means that the problem basically disappears and it probably will make translation simpler.
from go2js.
Sorry, I didn't notice that your example used t as the receiver. Yes, given that Go has explicit receiver identifiers then go2js can safely use that.
from go2js.
Related Issues (9)
- Crashes at translating a type which has not been yet defined HOT 2
- var has different scope in javascript HOT 1
- Emit raw JS code from .go (for wrapping existing JS libs) HOT 3
- const keyword unsupported in IE HOT 1
- Channels and gorountines in js HOT 1
- Generate CommonJS / AMD compatible .js files HOT 1
- Are you aware of GopherJS? HOT 2
- Is that possible to translate js to Go? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go2js.