-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Why javascript evaluation context inside a mixin is not equals the outter context? #1139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
@agatronic actual not browser and node, Im using WinLess a windows application to compile less file. Is there any possible to setup a global function that every corner in less can access it? |
winless probably executes the browser version.. have you tried attaching to |
@agatronic I print out the properties of |
less.js evaluates in a new object... https://github.com/cloudhead/less.js/blob/master/lib/less/tree/javascript.js#L19 I don't know much about wsh, but less doesn't define You might also want to look at #732 and ask for it to be re-instated |
@agatronic Thanks for your help. I have know where the problem is. First, WinLess is using node.js windows version, not WSH. So there is a Second, The reason function cannot accessed in a mixin is not because there are two different global context inside and outside mixin, It's because these functions are not define yet when needs them. I noticed that the javascript in mixins evaluated earlier than those are in root, So I changed function defination codes to:
All works well. And thank you again. |
I wrote some helper functions in root less file:
@randomFunctions : ~
(function(s){ var round = function(n,c){ c = c|0; return Math.round(n * Math.pow(10,c))/Math.pow(10,c); }; var random = function(s,e){ return Math.random() * (e - s) + s; }; global.r = function(s,e,u){ return round(random(s,e)) + u; }; return 'randomFunctions'; })(this)
;then I could generate random numbers using these functions:
.r{ opacity : ~
r(0,1)
; } outputs .rr{ opacity : 0.3; }but in a mixin:
.r(@i){
.r@{i} { opacity : ~
r(0,1)
; }}
.r(1);
compiler tells me 'Can not found r function in [object Object]'
so I guess the javascript evalution context inside a mixin is different with the context in root.
Will this be fixed in next version? or just add another way to pass a function inside mixin so I can release the power of javascript in less file?
The text was updated successfully, but these errors were encountered: