'this' keyword question

function {employee (age, salary)

Define dynamic instance variables

This.Age = age;

This.Salary = salary;

}

I see that the 'this' keyword is used to add a dynamic property to the instantiated object.

My question is that I also saw the following code.

function {employee (age, salary)

Define dynamic instance variables

_age = age;

_salary = salary;

}

What is the difference, or is it a question of preference or the naming convention?

Thank you

It's preferences of conventions, and it is not.

With regard to the parameters of class vs functions scopes properties go, I prefer the variables name bearing the same names for reasons of continuity.

In all cases, the use of this is needed, of course, when it is used the same names.

Also, I prefer convention when _variableName is used only for the private variables that have accessors (getters/setters) correspondents. In all other cases, I use just-mixed-case.

However, in some situations, we have flexibility.

For example, let's say we have class:

package
{

          public class SuperClass
          {
                    private var _age:Number;
                    private var _salary:Number;
                    public function SuperClass()
                    {

                    }

                    public function employee(age:Number, salary:Number):void {
                              _age = age;
                              _salary = salary;
                    }

                    public function get age():Number
                    {
                              return _age;
                    }

                    public function set age(value:Number):void
                    {
                              _age = value;
                    }

                    public function get salary():Number
                    {
                              return _salary;
                    }

                    public function set salary(value:Number):void
                    {
                              _salary = value;
                    }

          }

}

In the superclass, the scope has access to _age and _salary directly even if they are private. So - there is no need to use accessors directly.

Now here's a a class that extends the superclass:

package
{
          public class ExtendingClass extends SuperClass
          {

                    public function ExtendingClass()
                    {

                    }

                    public function employee2(age:Number, salary:Number):void
                    {
                              this.age = age;
                              this.salary = salary;
                    }

          }

}

This class doesn't have access to _age and _salary because they are private but the accessors are available. Therefore, we SHOULD use the "this" keyword

Above examples are not very practical but similar situations pop up constantly.

Tags: Adobe Animate

Similar Questions

  • This keyword

    I was wondering if I could use the keyword 'this' out of reach.  When I use this inside a function in my class he correctly refers to the MovieClip object.  When I use the trace (this); inside a function nested but I always get [object global].  I can't use this.this so my question is, are at - it another way to refer to an instance of my MovieClip without having to refer to an instance name?  Thanks in advance.

    You should not nest functions.  In general, AS3, use of 'this' is mostly useless.  If you use old habits, try to break.

  • Keyword question-how do mass you remove/change

    My workflow has changed because I have used the program and as such, my keyword process has changed as well.  I've been unsuccessful in changing/deleting of a key word on several files at the same time.  My current method:

    Select multiple files in a LIBRARY/FILM mode

    Select the Sync metadata button

    In the KEYWORDS section, add a Word

    It works very well for the addition, but if I select one of the words and delete it or change it, it don't not remove/change the word, he says just what I'm typing.

    Is there an easier way this vice file-by-file select/delete-change?

    You can make changes in mass of keywords in the keywords Panel. But you need the pictures selected in the library grid view - not in the film. Perhaps it is also the key to why your method of synchronization does not work for you. I know, it looks like a selection of several photos in the film must be the same by selecting them in the grid view, but it does not work like that.

    This approach is very taxing to the Lightroom Catalog, so I found that I have to be careful. Allow Lightroom finish ' accumulated metadata "before making a change. Make sure that you are using the "Add keywords". If you delete a keyword, make sure that you click in the keyword text entry box after deleting it also that the deletion can't.

    A change in this interactive mode can kick off a large number of database transactions if you let finish before you make another change.

    I used to use ACDSee Pro and the only way to change the metadata on more than one image was to use their synchronization tool. Adobe has been brave to allow users to directly.

  • _name for this keyword property

    When you use the keyword this inside an event handler it refers to the object that raised the event.

    For example if a sound object OnLoadInit fires, you can tell

    This.Play ();

    Is it possible to return the name of this body the way you can get the name of a clip

    IE somemovieclip_mc._name

    It is probably not as simple as that. There is a solution to probably several lines of code.
    However, it would be useful for a lot of debugging.
    Any help would be greatly appreciated.

    That is regrettable. I spent a lot of time trying to find a way to do it, but it doesn't seem to be any work around.

    Thanks for your help.

  • Keyword questions

    How can I add a keyword (or several) to multiple images?

    Is it possible to remove typos from the list of keywords with the keywords Manager?

    Thanks in advance

    Hans

    Select the photos and info - keywords apply to all selected photos

    Open keyword manager and click on edit - select the keyword you want to edit and then delete (click the sign-) or repair

    LN

  • I feel stupid asking this (microSD question)

    But how do I actually put files on my microSD card and NOT on the internal memory of the rocket itself?

    I'm sure it's something incredibly simple and I feel like a fool for asking this, but I have looked through the user guides, many other sources and this forum and can't seem to find out.

    Help? Please?

    If you are using windows and your player is in mode MSC (see settings), you should see 2 drives letters when you plug in the appliance. The first is for the internal memory, the second is for the SD card.

  • BlackBerry smartphones please deliver this stupid Question! / what I did?

    As I am still relatively new to the Blackberry.

    On my screen, I noticed something that I don't remember having seen it before, and I could have accidentally done it... Not sure!   You know where the time, almost Center screen and below who are day, month, and date? Beaneath straight you can sometimes get an icon of a telephone receiver with however many appeals you may have missed or that you have a sms, message, etc... Well, I have an icon of a yellow globe, in fact the icon shows with the number 1 in front of him!

    Do not remember that it is there before, can someone tell me what this means and how to remove it.

    Still a newbie!

    Thank you

    Charlene

    This is a saved search browser... go to messages then choose the browser messages folder and it will be there and select and delete it.

  • How to deal with the "Trust this PC question?"

    So I cleaned my laptop because of a problem that could not be repaired (Windows 8.1) disorder (Windows 10) back to Windows 8. So I checked my PC and it says "proud of this PC. I did the newspaper and codes and that brings me to this:

    Secure devices

    Visit https://account.live.com/trustdevice to Internet Explorer from the device of Windows 8 that you do not want to trust.

    So I did the same with Internet Explorer and it gives me this:

    Secure devices

    Visit https://account.live.com/trustdevice to Internet Explorer from the device of Windows 8 that you do not want to trust.

    Nothing happens.

    I am confused and stuck. I don't know how to fix it. Can you give me ideas to fix?

    Never mind. Windows 8.1 update pretty much fixed my problem.

  • 'this' keyword and buttons

    If I create a simple flash document, draw a rectangle, convert it to a clip, the clip of the give an instance name, and then put this code on this:

    Quote:
    on (release) {}
    trace (this ._name);
    }
  • Please if you have one coming 11 Pro, answer me this quick question - related /screen fans

    Are supposed to be two fans in the 11 venue? In particular the i3/i5 models?

    I noticed that I don't hear a fan, from the right wind, but on the other side is quiet.

    Also, when I have the screen displays something like XBMC or certain types of film, there is a light buzzing/grinding noise coming from the location of the vent on the left, as if he were a fan turning, but it is soft or broken. If there is no fan, so maybe it's just the sound of the screen running at high frequency - or maybe it's the wireless card?

    Thank you

    One fan and it's on the right side - where is the processor!

  • To be or not to be virtual memory; is this a question?

    Some people claim that systems with 8 GB of RAM or more do not need more than 800 MB of virtual memory to cover failures of the system. Others claim that virtual memory is used for something else that the permutation and must therefore be kept to the suggested amount. Some people claim that virtual memory is essential to protect against leaks of memory, but that wouldn't be delaying the inevitable. I've built systems with 16 GB of RAM and only 800 MB of virtual memory and never had a problem because she.

    It gives 8 or even 16 GB of RAM, virtual memory is the computer equivalent of a human appendage, that is, it used to be important a long time ago, but now it's just an object of ridicule?

    P.S. If the virtual memory is important, please give specific examples.

    PC

    In the case of a computer crash if there is little or not the cause of the accident of virtual memory cannot be written to disk so to diagnose a computer problem is made more difficult without it.

  • Need to answer to this interview question where

    Hi all

    Consider that we have 2 ESXi hosts added to the active cluster with no HA and DRS. If one of the servers goes down how you will get the list of virtual machines, which was built on the ESXi host failed to recover on another smart host?

    The inventory of your cluster is in a SQL database backend, you can directly query the SQL DB...

    -Get the RAW data for all virtual machines...

    SELECT v.NAME, v.DNS_NAME, v.IP_ADDRESS, v.MEM_SIZE_MB, v.NUM_VCPU, v.GUEST_OS, v.DESCRIPTION, v.ANNOTATION, v.VMID, f.FIELDVALUE

    V VPXV_VMS AS LEFT OUTER JOIN

    VPXV_VM_FIELDS AS f ON v.VMID = f.VMID AND f.FIELDID = 142

    ORDER BY v.NAME

    Someone correct me if I'm wrong, but normally vCenter show out grey of the virtual machine.

  • Gap between the number of keyword tag and the actual number of photos with this tag

    I have the keyword tag, number beside her guess of "reflect the total number of pictures that use the tag", in my case it is 6009. " But when I consult the catalogue of this keyword tag, or simply click on the arrow next to the keyword tag, it shows me only 5911 photos with the keyword tag. I don't understand why there is difference of 98 photos.

    How can I find that 98 photos? Or how I can reconcile number next to the keyword tag?

    Thank you!

    98 photos can be hidden in chimneys collapsed.  Make Photo > stacking > expand all stacks.

  • I'm embarrassed to even ask the question, but: what 'this' refers to?

    I'm losing the plot trying to Google "this." It is not just to work. BUT I found a description by looking at the index of the ActionScript 3.0 documentation. http://help.Adobe.com/en_US/FlashPlatform/reference/ActionScript/3/statements.html#this

    Here it is:

    "A reference to a method that contains the object. When a script is executed, the this keyword refers to the object that contains the script. Inside a method body, the this keyword refers to the instance of the class that contains the called method. »

    for example, to access a property or method of a method in the same category, you type: this.method () or this.property, right? "I'm sure that it works without '.', but it confuses me because I learned PHP prior to ActionScript, and you need always"this->"in this case.

    In addition, that the Eggplant "this" refers to when it is used for the main timeline (not within a class)?

    PostScript:

    Sorry for the word 'this' so... cela.

    1. I think that the explanation of Ned linking this keyword to the timeline is limited because timeline can be a MovieClip instance attribute only, while the keyword this refers to the scope of the proceeding of ANY AS3 object. Main index is the INSTANCE of word. So, this keyword is much broader meaning and usage.

    2. Although it is true that among the amenities of this isn't to use it as an associative array, I would not that it is the main use. In my view, well-designed OOP applications the is not necessary for the associative array syntax because there are many more effective approaches to reference properties.

    "I won't need to use the statement 'this' to access the other methods and properties in the same class."

    You should review.

    Some examples when this is useful:

    A. methods parameters vs example properties/methods, naming conventions.

    In of this example of method parameter property and an instance with the same name, but there is no confusion:

    private var width:Number;
    
    public function changeWidth(width:Number):void {
        this.width = width;
    }
    

    (B) the property of the instance and variable from the method names are the same. Once again, the references are clear:

    private var myVariable:String;
    
    private function doSomething():void {
        var myVariable:String = "BLAH";
        this.myVariable = "ANOTHER BLAH";
    }
    

    Also, although AS3 does not support overloading, you can call the methods their reach to this or super.

    override protected function myFunction():void {
    
    }
    
    private function callMyFunction():void {
        this.myFunction();
        super.myFunction();
    }
    

    In addition, when static vs. instance possedantes/methods are used - can not brought those static for this which is sometimes useful as well.

  • What is the function of "main()" into a flex application?  If this is not the case, how to exploit the "message pump' access the CPU?

    I'm learning Flex and trying to write a VERY simple app to put random dots or lines on a mx:Canvas.

    I can't know where in fact the code in the code canvas.graphics.lineTo(x,y).

    Either I want to enter the processor in the "main() function" of the app or draw a point/line for every CPU in a message (as for Windows applications) pump.

    I tried to add this:

    < mx:Canvas id = "canvas >"

    ...

    < mx:Script >
    <! [CDATA]

    canvas.graphics.lineTo (Math.random () * 300, Math.random () * 300);
    []] >
    < / mx:Script >

    but the compiler Flex says:

    1120: access of undefined property canvas.

    How is he can't find the canvas?

    If I add the keyword 'this' like this:

    this.canvas.graphics.lineTo (...)

    I get:

    1042: the this keyword can not be used in static methods. It can only be used in instance methods, function closures and the global code.

    Where should I put the actual graph code or a loop to draw lines? Help!

    Pete

    If this post answers your question or assistance, please mark it as such.

    Your drawing code must be in a function, and in the following code, it is called application creationComplete. You cannot draw directly on a canvas (at least I couldn't), so match zero on a Sprite or a SpriteAsset, wrap it in a UIComponent, so it can be added to the container and then adds the UIComponet to the canvas.

    
      
        
      
      
    
    

Maybe you are looking for