You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Harbs <ha...@gmail.com> on 2019/12/03 17:35:53 UTC

this in closures

I recently started getting some of these warnings:

Warning: Encountered this keyword within closure. Value of this will not be the same as enclosing scope.

I understand the desire to have this warning, but I think it either needs to be smarter or be easily turned off.

I have a case where I have Object.defineProperty which takes a function that needs to refer to “this”. That’s a valid use of this within a “closure”, and I can’t find an easy way of turning the warning off for that use case.

Harbs

Re: this in closures

Posted by Josh Tynjala <jo...@bowlerhat.dev>.
Hmmm... odd. However, I'm not sure that it's actually treated differently
from other warnings.

If I create a variable without a type, like this:

var zzz;

I also see the warning at the end, after the success message, like this:

The project 'RoyaleClosureThisWarning' has been successfully compiled.
RoyaleClosureThisWarning.as(26): col: 8 Warning: variable 'zzz' has no type
declaration.

I can see that MXMLJSCRoyale doesn't print the error/warnings until after
the MXMLRoyalePublisher.publish() returns, and that's where the success
message is printed. It seems like maybe MXMLRoyalePublisher shouldn't be
printing that success message, and it should let something further up the
chain report success or failure.

--
Josh Tynjala
Bowler Hat LLC <https://bowlerhat.dev>


On Mon, Dec 9, 2019 at 2:28 AM Harbs <ha...@gmail.com> wrote:

> Why does this warning show up at the very end of the console output
> (different than all other errors and warnings)?
>
> > On Dec 4, 2019, at 1:29 AM, Josh Tynjala <jo...@bowlerhat.dev>
> wrote:
> >
> > It's not possible at this time.
> >
> > Java has an annotation for suppressing warnings locally:
> >
> > @SuppressWarnings({"unchecked", "deprecated"})
> >
> > More info: https://www.baeldung.com/java-suppresswarnings
> >
> > It might be interesting to allow something similar in AS3:
> >
> > [SuppressWarnings(this-within-closure,assignment-within-conditional)]
> >
> > I'm not sure if dashes are allowed in AS3 metadata attributes, but
> > basically, the idea is to have the attribute names match the existing
> > compiler options for each type of warning that can be suppressed.
> >
> > --
> > Josh Tynjala
> > Bowler Hat LLC <https://bowlerhat.dev>
> >
> >
> > On Tue, Dec 3, 2019 at 10:09 AM Harbs <ha...@gmail.com> wrote:
> >
> >> What about locally?
> >>
> >>> On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev>
> >> wrote:
> >>>
> >>> You can turn it off with the following compiler option:
> >>> -warn-this-within-closure=false
> >>>
> >>> --
> >>> Josh Tynjala
> >>> Bowler Hat LLC <https://bowlerhat.dev>
> >>>
> >>>
> >>> On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
> >>>
> >>>> I recently started getting some of these warnings:
> >>>>
> >>>> Warning: Encountered this keyword within closure. Value of this will
> not
> >>>> be the same as enclosing scope.
> >>>>
> >>>> I understand the desire to have this warning, but I think it either
> >> needs
> >>>> to be smarter or be easily turned off.
> >>>>
> >>>> I have a case where I have Object.defineProperty which takes a
> function
> >>>> that needs to refer to “this”. That’s a valid use of this within a
> >>>> “closure”, and I can’t find an easy way of turning the warning off for
> >> that
> >>>> use case.
> >>>>
> >>>> Harbs
> >>
> >>
>
>

Re: this in closures

Posted by Harbs <ha...@gmail.com>.
Why does this warning show up at the very end of the console output (different than all other errors and warnings)?

> On Dec 4, 2019, at 1:29 AM, Josh Tynjala <jo...@bowlerhat.dev> wrote:
> 
> It's not possible at this time.
> 
> Java has an annotation for suppressing warnings locally:
> 
> @SuppressWarnings({"unchecked", "deprecated"})
> 
> More info: https://www.baeldung.com/java-suppresswarnings
> 
> It might be interesting to allow something similar in AS3:
> 
> [SuppressWarnings(this-within-closure,assignment-within-conditional)]
> 
> I'm not sure if dashes are allowed in AS3 metadata attributes, but
> basically, the idea is to have the attribute names match the existing
> compiler options for each type of warning that can be suppressed.
> 
> --
> Josh Tynjala
> Bowler Hat LLC <https://bowlerhat.dev>
> 
> 
> On Tue, Dec 3, 2019 at 10:09 AM Harbs <ha...@gmail.com> wrote:
> 
>> What about locally?
>> 
>>> On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev>
>> wrote:
>>> 
>>> You can turn it off with the following compiler option:
>>> -warn-this-within-closure=false
>>> 
>>> --
>>> Josh Tynjala
>>> Bowler Hat LLC <https://bowlerhat.dev>
>>> 
>>> 
>>> On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
>>> 
>>>> I recently started getting some of these warnings:
>>>> 
>>>> Warning: Encountered this keyword within closure. Value of this will not
>>>> be the same as enclosing scope.
>>>> 
>>>> I understand the desire to have this warning, but I think it either
>> needs
>>>> to be smarter or be easily turned off.
>>>> 
>>>> I have a case where I have Object.defineProperty which takes a function
>>>> that needs to refer to “this”. That’s a valid use of this within a
>>>> “closure”, and I can’t find an easy way of turning the warning off for
>> that
>>>> use case.
>>>> 
>>>> Harbs
>> 
>> 


Re: this in closures

Posted by Greg Dove <gr...@gmail.com>.
Harbs, does this warning show for both swf and js?
I think that stuff is only for js.

On Wed, Dec 4, 2019 at 8:41 PM Harbs <ha...@gmail.com> wrote:

> What about adding it to JSRoyaleEmitterTokens — similar to
> @royalesuppresspublicvarwarning?
>
>
> > On Dec 4, 2019, at 1:29 AM, Josh Tynjala <jo...@bowlerhat.dev>
> wrote:
> >
> > It's not possible at this time.
> >
> > Java has an annotation for suppressing warnings locally:
> >
> > @SuppressWarnings({"unchecked", "deprecated"})
> >
> > More info: https://www.baeldung.com/java-suppresswarnings
> >
> > It might be interesting to allow something similar in AS3:
> >
> > [SuppressWarnings(this-within-closure,assignment-within-conditional)]
> >
> > I'm not sure if dashes are allowed in AS3 metadata attributes, but
> > basically, the idea is to have the attribute names match the existing
> > compiler options for each type of warning that can be suppressed.
> >
> > --
> > Josh Tynjala
> > Bowler Hat LLC <https://bowlerhat.dev>
> >
> >
> > On Tue, Dec 3, 2019 at 10:09 AM Harbs <ha...@gmail.com> wrote:
> >
> >> What about locally?
> >>
> >>> On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev>
> >> wrote:
> >>>
> >>> You can turn it off with the following compiler option:
> >>> -warn-this-within-closure=false
> >>>
> >>> --
> >>> Josh Tynjala
> >>> Bowler Hat LLC <https://bowlerhat.dev>
> >>>
> >>>
> >>> On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
> >>>
> >>>> I recently started getting some of these warnings:
> >>>>
> >>>> Warning: Encountered this keyword within closure. Value of this will
> not
> >>>> be the same as enclosing scope.
> >>>>
> >>>> I understand the desire to have this warning, but I think it either
> >> needs
> >>>> to be smarter or be easily turned off.
> >>>>
> >>>> I have a case where I have Object.defineProperty which takes a
> function
> >>>> that needs to refer to “this”. That’s a valid use of this within a
> >>>> “closure”, and I can’t find an easy way of turning the warning off for
> >> that
> >>>> use case.
> >>>>
> >>>> Harbs
> >>
> >>
>
>

Re: this in closures

Posted by Harbs <ha...@gmail.com>.
What about adding it to JSRoyaleEmitterTokens — similar to @royalesuppresspublicvarwarning?


> On Dec 4, 2019, at 1:29 AM, Josh Tynjala <jo...@bowlerhat.dev> wrote:
> 
> It's not possible at this time.
> 
> Java has an annotation for suppressing warnings locally:
> 
> @SuppressWarnings({"unchecked", "deprecated"})
> 
> More info: https://www.baeldung.com/java-suppresswarnings
> 
> It might be interesting to allow something similar in AS3:
> 
> [SuppressWarnings(this-within-closure,assignment-within-conditional)]
> 
> I'm not sure if dashes are allowed in AS3 metadata attributes, but
> basically, the idea is to have the attribute names match the existing
> compiler options for each type of warning that can be suppressed.
> 
> --
> Josh Tynjala
> Bowler Hat LLC <https://bowlerhat.dev>
> 
> 
> On Tue, Dec 3, 2019 at 10:09 AM Harbs <ha...@gmail.com> wrote:
> 
>> What about locally?
>> 
>>> On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev>
>> wrote:
>>> 
>>> You can turn it off with the following compiler option:
>>> -warn-this-within-closure=false
>>> 
>>> --
>>> Josh Tynjala
>>> Bowler Hat LLC <https://bowlerhat.dev>
>>> 
>>> 
>>> On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
>>> 
>>>> I recently started getting some of these warnings:
>>>> 
>>>> Warning: Encountered this keyword within closure. Value of this will not
>>>> be the same as enclosing scope.
>>>> 
>>>> I understand the desire to have this warning, but I think it either
>> needs
>>>> to be smarter or be easily turned off.
>>>> 
>>>> I have a case where I have Object.defineProperty which takes a function
>>>> that needs to refer to “this”. That’s a valid use of this within a
>>>> “closure”, and I can’t find an easy way of turning the warning off for
>> that
>>>> use case.
>>>> 
>>>> Harbs
>> 
>> 


Re: this in closures

Posted by Josh Tynjala <jo...@bowlerhat.dev>.
It's not possible at this time.

Java has an annotation for suppressing warnings locally:

@SuppressWarnings({"unchecked", "deprecated"})

More info: https://www.baeldung.com/java-suppresswarnings

It might be interesting to allow something similar in AS3:

[SuppressWarnings(this-within-closure,assignment-within-conditional)]

I'm not sure if dashes are allowed in AS3 metadata attributes, but
basically, the idea is to have the attribute names match the existing
compiler options for each type of warning that can be suppressed.

--
Josh Tynjala
Bowler Hat LLC <https://bowlerhat.dev>


On Tue, Dec 3, 2019 at 10:09 AM Harbs <ha...@gmail.com> wrote:

> What about locally?
>
> > On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev>
> wrote:
> >
> > You can turn it off with the following compiler option:
> > -warn-this-within-closure=false
> >
> > --
> > Josh Tynjala
> > Bowler Hat LLC <https://bowlerhat.dev>
> >
> >
> > On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
> >
> >> I recently started getting some of these warnings:
> >>
> >> Warning: Encountered this keyword within closure. Value of this will not
> >> be the same as enclosing scope.
> >>
> >> I understand the desire to have this warning, but I think it either
> needs
> >> to be smarter or be easily turned off.
> >>
> >> I have a case where I have Object.defineProperty which takes a function
> >> that needs to refer to “this”. That’s a valid use of this within a
> >> “closure”, and I can’t find an easy way of turning the warning off for
> that
> >> use case.
> >>
> >> Harbs
>
>

Re: this in closures

Posted by Harbs <ha...@gmail.com>.
What about locally?

> On Dec 3, 2019, at 7:39 PM, Josh Tynjala <jo...@bowlerhat.dev> wrote:
> 
> You can turn it off with the following compiler option:
> -warn-this-within-closure=false
> 
> --
> Josh Tynjala
> Bowler Hat LLC <https://bowlerhat.dev>
> 
> 
> On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:
> 
>> I recently started getting some of these warnings:
>> 
>> Warning: Encountered this keyword within closure. Value of this will not
>> be the same as enclosing scope.
>> 
>> I understand the desire to have this warning, but I think it either needs
>> to be smarter or be easily turned off.
>> 
>> I have a case where I have Object.defineProperty which takes a function
>> that needs to refer to “this”. That’s a valid use of this within a
>> “closure”, and I can’t find an easy way of turning the warning off for that
>> use case.
>> 
>> Harbs


Re: this in closures

Posted by Josh Tynjala <jo...@bowlerhat.dev>.
You can turn it off with the following compiler option:
-warn-this-within-closure=false

--
Josh Tynjala
Bowler Hat LLC <https://bowlerhat.dev>


On Tue, Dec 3, 2019 at 9:36 AM Harbs <ha...@gmail.com> wrote:

> I recently started getting some of these warnings:
>
> Warning: Encountered this keyword within closure. Value of this will not
> be the same as enclosing scope.
>
> I understand the desire to have this warning, but I think it either needs
> to be smarter or be easily turned off.
>
> I have a case where I have Object.defineProperty which takes a function
> that needs to refer to “this”. That’s a valid use of this within a
> “closure”, and I can’t find an easy way of turning the warning off for that
> use case.
>
> Harbs