Comments (7)
or at least allow this construction to work:
post data, {
some code
}.bind(this)
actually it throws: Module build failed: Parse error at [981:1]: Unexpected '.'
from imba.
err, i meant
post data, { |response|
some code
}.bind(this)
from imba.
We do consider adding a func-keyword (or similar) - that behaves exactly like do but without binding self (fat arrow). It's not totally clear to me what you are trying to achieve -- but you can use this
in imba as well. this
will always refer to the real this
, just like in plain javascript. You can also export declared methods with def
in imba. These are closed scopes (self is not brought in from outer scope). So if I understand you correctly, you might want to do:
export def save data
post(data) do console.log('something')
This compiles to:
function save(data){
return this.post(data,function() { return console.log('something'); });
}; exports.save = save;
from imba.
I've promised to release the new site (with docs) this week, and we'll explain it there in more detail. But yes, lambda-style blocks are 'open', where their implicit self refers to the outer 'closed' scope. You can still use this
explicitly though, it will never refer to anything else than the actual js this
.
Method declarations (def) are 'closed' scopes, where the implicit self is not brought in from outer scopes.
And some more undocumented syntax... As you mentioned:
post data, { |response| some code }.bind(this)
is not valid in imba, we use regular parens instead:
post data, (|response|
some code
).bind(this)
This only works for methods with arguments though, so it is a rather clumsy syntax which might be deprecated in favour of the ruby-like syntax you wrote. To be on the safe side, you could just do this:
post data, (do
some code
).bind(this)
# with parens
post data, (do |res|
some code
).bind(this)
from imba.
exactly, but inside function() { return console.log('something'); }
the this
will be Window,
that's the issue.
my idea was do
to generate functions like this:
function() { return console.log('something'); }.bind(this)
from imba.
The implicit self of a do block is always the closest 'closed' scope, not the outermost. def save has a closed scope, which the inner do will refer to. So in your example this
will not be the window.
export def save data
post(data) do
self # self here is the method on which save is called
compiles to
function save(data){
var self = this;
return this.post(data,function() {
return self; // self here is the context on which save is called
});
}; exports.save = save;
This is practically the same as:
function save(data){
return this.post(data,function() {
return this; // self here is the context on which save is called
}.bind(this));
}; exports.save = save;
Except we get better performance, and we can still use the actual this
in addition to the implied self
.
Your idea is good, and it is essentially what we do, except we don't use bind (mostly for performance reasons), we cache a reference to bind instead. One confusing thing about our examples is that we use console, which is a globally exported variable, so it does (as you can see) not compile to self.console.log(...)
from imba.
ok, wonderful,
export def
works perfect!
self
is just what it is expected to be.
thank you.
Imba is impressive!
hoping it is here to stay.
keep doing marketing.
nowadays marketing is most important language feature :)
from imba.
Related Issues (20)
- npx imba create fails (Windows) HOT 1
- The new color decimal tone steps do not work with the hue color keyword.
- unitless size not working in paddings
- [CSS] Advanced CSS units
- [CSS] Support CSS values with / and spaces HOT 1
- Components that inherit from another class do not render with the appropriate CSS class HOT 1
- input's native "list" property throws error
- Draggable HTML attribute is set to "true" when it equals "false" as a string HOT 1
- [Docs] No documentation for templates. imba create points to an empty page.
- `imba create ; pnpm i` installs imba 0.9.0
- ease (Transitions) eat mouse event HOT 5
- One more or up to three more steps in Imba clever syntax
- + and ~ css selector doesn't work with indentated declarations HOT 1
- Passing objects without {} sometimes ambiguous HOT 5
- window.print not working HOT 3
- change to value of property in an `@observable` object doesn't trigger `@autorun`
- Router hooks
- bxs: outline should support inset, and suggestion to add bxs:stroke (inset) for 1px shadows
- interpolation of values to hue not working as espected
- Feature Request: Support Prolog Style op/3 User Defined Operators
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 imba.