Javascript function evaluates to true even when it returns false in Lightning Helper
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I am trying to encapsulate logic to determine if a button is visible inside the second argument via anonymous function:
component.set("!v.assignButtonVisible", function()
console.log('Do we get here?');
return false;
);
However, the code inside the function
never executes and the attribute is set to true.
The only reason I can think of is at run-time, when function() ...
resolves, it is not null
and therefore is interpreted as true
.
Is what I'm trying to do possible? Can I call a named or anonymous function to get the value I'm looking for, or is my only option to create and set a var
before calling component.set( ... )
?
lightning-components javascript
add a comment |Â
up vote
1
down vote
favorite
I am trying to encapsulate logic to determine if a button is visible inside the second argument via anonymous function:
component.set("!v.assignButtonVisible", function()
console.log('Do we get here?');
return false;
);
However, the code inside the function
never executes and the attribute is set to true.
The only reason I can think of is at run-time, when function() ...
resolves, it is not null
and therefore is interpreted as true
.
Is what I'm trying to do possible? Can I call a named or anonymous function to get the value I'm looking for, or is my only option to create and set a var
before calling component.set( ... )
?
lightning-components javascript
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to encapsulate logic to determine if a button is visible inside the second argument via anonymous function:
component.set("!v.assignButtonVisible", function()
console.log('Do we get here?');
return false;
);
However, the code inside the function
never executes and the attribute is set to true.
The only reason I can think of is at run-time, when function() ...
resolves, it is not null
and therefore is interpreted as true
.
Is what I'm trying to do possible? Can I call a named or anonymous function to get the value I'm looking for, or is my only option to create and set a var
before calling component.set( ... )
?
lightning-components javascript
I am trying to encapsulate logic to determine if a button is visible inside the second argument via anonymous function:
component.set("!v.assignButtonVisible", function()
console.log('Do we get here?');
return false;
);
However, the code inside the function
never executes and the attribute is set to true.
The only reason I can think of is at run-time, when function() ...
resolves, it is not null
and therefore is interpreted as true
.
Is what I'm trying to do possible? Can I call a named or anonymous function to get the value I'm looking for, or is my only option to create and set a var
before calling component.set( ... )
?
lightning-components javascript
lightning-components javascript
asked 1 hour ago
Swisher Sweet
1,77311130
1,77311130
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
You actually put the function in to the attribute, not the return value, because the function was never "called" (executed). If you want to call such a function inline, you can, but you need to actually call it. This just requires a few more parentheses:
component.set("!v.assignButtonVisible", (function()
console.log('Do we get here?');
return false;
)());
We put the entire function inside parentheses, then give it an empty parameter list. That pattern looks like:
(function(...) ... )(...)
You can put stuff in where the dots are (parameters and code body). This is called the "self-executing anonymous function" pattern.
I was so close. In one of my tries I wrapped the(function()...)
but forgot the last()
. Thank you!
â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You actually put the function in to the attribute, not the return value, because the function was never "called" (executed). If you want to call such a function inline, you can, but you need to actually call it. This just requires a few more parentheses:
component.set("!v.assignButtonVisible", (function()
console.log('Do we get here?');
return false;
)());
We put the entire function inside parentheses, then give it an empty parameter list. That pattern looks like:
(function(...) ... )(...)
You can put stuff in where the dots are (parameters and code body). This is called the "self-executing anonymous function" pattern.
I was so close. In one of my tries I wrapped the(function()...)
but forgot the last()
. Thank you!
â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
add a comment |Â
up vote
4
down vote
You actually put the function in to the attribute, not the return value, because the function was never "called" (executed). If you want to call such a function inline, you can, but you need to actually call it. This just requires a few more parentheses:
component.set("!v.assignButtonVisible", (function()
console.log('Do we get here?');
return false;
)());
We put the entire function inside parentheses, then give it an empty parameter list. That pattern looks like:
(function(...) ... )(...)
You can put stuff in where the dots are (parameters and code body). This is called the "self-executing anonymous function" pattern.
I was so close. In one of my tries I wrapped the(function()...)
but forgot the last()
. Thank you!
â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You actually put the function in to the attribute, not the return value, because the function was never "called" (executed). If you want to call such a function inline, you can, but you need to actually call it. This just requires a few more parentheses:
component.set("!v.assignButtonVisible", (function()
console.log('Do we get here?');
return false;
)());
We put the entire function inside parentheses, then give it an empty parameter list. That pattern looks like:
(function(...) ... )(...)
You can put stuff in where the dots are (parameters and code body). This is called the "self-executing anonymous function" pattern.
You actually put the function in to the attribute, not the return value, because the function was never "called" (executed). If you want to call such a function inline, you can, but you need to actually call it. This just requires a few more parentheses:
component.set("!v.assignButtonVisible", (function()
console.log('Do we get here?');
return false;
)());
We put the entire function inside parentheses, then give it an empty parameter list. That pattern looks like:
(function(...) ... )(...)
You can put stuff in where the dots are (parameters and code body). This is called the "self-executing anonymous function" pattern.
edited 1 hour ago
answered 1 hour ago
sfdcfox
226k10173388
226k10173388
I was so close. In one of my tries I wrapped the(function()...)
but forgot the last()
. Thank you!
â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
add a comment |Â
I was so close. In one of my tries I wrapped the(function()...)
but forgot the last()
. Thank you!
â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
I was so close. In one of my tries I wrapped the
(function()...)
but forgot the last ()
. Thank you!â Swisher Sweet
1 hour ago
I was so close. In one of my tries I wrapped the
(function()...)
but forgot the last ()
. Thank you!â Swisher Sweet
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
@SwisherSweet Yeah, it's kind of unusual if you're not used to using this pattern, really easy to miss.
â sfdcfox
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f232393%2fjavascript-function-evaluates-to-true-even-when-it-returns-false-in-lightning-he%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password