Local VariablesLocal variables are used to track information temporari การแปล - Local VariablesLocal variables are used to track information temporari ไทย วิธีการพูด

Local VariablesLocal variables are

Local Variables
Local variables are used to track information temporarily within the physical confines
of a constructor method, an instance method, a static method, or a function.
We haven’t studied instance methods, static methods, or functions yet so for now
we’ll focus on local variables in constructor methods.
To create a local variable within a constructor method, we use a variable definition,
as shown in the following generalized code. Notice that the definition starts with the
keyword var and, by convention, ends in a semicolon, as do all directives that do not
include a block statement. The semicolon indicates the end of the directive, much
like the period at the end of a sentence in a natural language.
class SomeClass {
public function SomeClass ( ) {
var identifier = value;
}
}
In the preceding code, identifier is the local variable’s name, and value is the value
associated with that variable. Together, the equals sign and the value are known as
the variable initializer because they determine the initial value of the variable.
20 | Chapter 1: Core Concepts
Associating a variable with a value is known as assigning, setting, or
writing the variable’s value.
When the variable initializer is omitted, ActionScript automatically assigns the variable
a default value. Default values for variables are discussed in Chapter 8.
A local variable can be used within the method or function that contains its definition
only. When the method or function finishes executing, the local variable expires
and can no longer be used by the program.
Let’s create a local variable to refer to the VirtualPet object we created earlier in the
VirtualZoo constructor. We’ll name the local variable pet, and we’ll use an initializer
to associate it with the VirtualPet object. Here’s the code:
package zoo {
public class VirtualZoo {
public function VirtualZoo ( ) {
var pet = new VirtualPet;
}
}
}
Having associated the local variable pet with a VirtualPet object, we can now use
that variable to refer to, and therefore control, that object. However, currently our
VirtualPet object can’t actually do anything because we haven’t programmed its
functionality. We’ll start to rectify that shortcoming in the next section by giving pets
the ability to have nicknames.
Instance Variables
Earlier we learned that a class describes the characteristics and behavior of a particular
type of object. In object-oriented programming terms, a “characteristic” is a specific
piece of information (i.e., value) that describes some aspect of an object—such
as its width, speed, or color. To keep track of an object’s characteristics, we use
instance variables.
An instance variable is a variable attached to a particular object. Typically, each
instance variable describes a characteristic of the object to which it is attached. For
example, an instance variable might be the identifier width associated with the value
150, describing the size of the button object in an interface. Or, an instance variable
might be the identifier shippingAddress associated with the value “34 Somewhere
St,” describing the destination of a product-order object.
Instance variables are created using variable definitions directly within class definitions,
as shown in the following generalized code
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (ไทย) 1: [สำเนา]
คัดลอก!
ตัวแปรท้องถิ่น
ตัวแปรเฉพาะที่ใช้ในการติดตามข้อมูลชั่วคราวภายในขอบเขตทางกายภาพ
ตัวสร้างวิธี วิธีการอินสแตนซ์ วิธีคง หรือฟังก์ชัน
เราไม่ได้ศึกษาวิธีการอินสแตนซ์ วิธีการแบบคง หรือฟังก์ชัน ยังนั้นตอนนี้
เราจะเน้นตัวแปรภายในตัวสร้างวิธี
เพื่อสร้างตัวแปรท้องถิ่นภายในตัวสร้างวิธี เราใช้ตัวแปรคำนิยาม,
ดังต่อไปนี้ในรหัสการตั้งค่าทั่วไป ประกาศที่กำหนดเริ่มต้น
var สำคัญถึง โดยประชุม เครื่องหมายอัฒภาค ทำคำสั่งทั้งหมดที่ไม่
รวมรายการบล็อก ระบุท้ายคำสั่ง มาก
ชอบช่วงท้ายของประโยคในภาษา
คลา SomeClass {
สาธารณะฟังก์ชัน SomeClass () {
รหัส var =ค่า;
}
}
ในรหัสก่อนหน้านี้ ระบุชื่อของตัวแปรท้องถิ่น และค่า ค่า
เกี่ยวข้องกับตัวแปรนั้น กัน เครื่องหมายเท่ากับและค่าจะเรียกว่า
ตัวแปรเนื่องจากกำหนดค่าเริ่มต้นของตัวแปร
20 | บทที่ 1: แนวคิดหลัก
เชื่อมโยงตัวแปร มีค่าเรียกว่ากำหนด ตั้ง หรือ
เขียนค่าของตัวแปร
เมื่อไม่ใส่ตัวแปร ActionScript กำหนดตัวแปรโดยอัตโนมัติ
ค่าเริ่มต้น ค่าเริ่มต้นสำหรับตัวแปรจะกล่าวถึงในบทที่ 8.
สามารถใช้ตัวแปรท้องถิ่นภายในวิธีการหรือฟังก์ชันที่ประกอบด้วยข้อกำหนดของ
เท่านั้น เมื่อวิธีการฟังก์ชันเสร็จสิ้นดำเนินการ ตัวแปรท้องถิ่นหมดอายุ
และไม่สามารถถูกใช้ โดยโปรแกรม
ของให้สร้างตัวแปรท้องถิ่นอ้างอิงไปยังวัตถุ VirtualPet ที่เราสร้างไว้ก่อนหน้านี้ในการ
ตัวสร้าง VirtualZoo เราจะตั้งชื่อสัตว์เลี้ยงตัวแปรท้องถิ่น และเราจะใช้เป็นตัว
เพื่อเชื่อมโยงกับวัตถุ VirtualPet นี่คือรหัส:
สัตว์แพคเกจ {
สาธารณะคลา VirtualZoo {
สาธารณะฟังก์ชัน VirtualZoo () {
สัตว์ var = VirtualPet ใหม่;
}
}
}
มีสัมพันธ์สัตว์เลี้ยงตัวแปรท้องถิ่นกับวัตถุ VirtualPet เราสามารถใช้
แปรที่ถึง และดังนั้น ควบคุม วัตถุได้ อย่างไรก็ตาม ในปัจจุบันของเรา
VirtualPet วัตถุจริงทำอะไรไม่ได้เนื่องจากเรายังไม่ได้โปรแกรมของ
ฟังก์ชันได้ เราจะเริ่มคงที่ในส่วนถัดไปแก้ไขให้สัตว์เลี้ยง
สามารถได้เล่น
ตัวแปรอินสแตนซ์
ก่อนหน้านี้เราได้เรียนรู้ว่า เรียนอธิบายถึงลักษณะและพฤติกรรมทั้งหมด
ชนิดของวัตถุ เชิงวัตถุข้อเขียน "ลักษณะเฉพาะ" เป็นการ
ข้อมูล (เช่น ค่า) ที่อธิบายบางแง่มุมของวัตถุ — เช่น
เป็นความกว้าง ความเร็ว หรือสี การติดตามลักษณะของวัตถุ เราใช้
อินสแตนซ์ตัวแปร.
ตัวอย่างตัวแปรเป็นตัวแปรที่แนบกับวัตถุที่เฉพาะเจาะจง โดยปกติ แต่ละ
อินสแตนซ์ตัวแปรอธิบายลักษณะของวัตถุที่มันอยู่ สำหรับ
ตัวอย่าง ตัวแปรอินสแตนซ์อาจระบุความกว้างสัมพันธ์กับค่า
150 อธิบายขนาดของวัตถุปุ่มในอินเทอร์เฟซ หรือ ตัวแปรอินสแตนซ์
อาจ shippingAddress รหัสที่เกี่ยวข้องกับค่า " 34 บาง
เซนต์, " อธิบายปลายทางของการสั่งผลิตภัณฑ์วัตถุ
สร้างตัวแปรอินสแตนซ์โดยใช้นิยามตัวแปรโดยตรงภายในข้อกำหนดคลาส,
ดังต่อไปนี้ในรหัสการตั้งค่าทั่วไป
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 2:[สำเนา]
คัดลอก!
Local Variables
Local variables are used to track information temporarily within the physical confines
of a constructor method, an instance method, a static method, or a function.
We haven’t studied instance methods, static methods, or functions yet so for now
we’ll focus on local variables in constructor methods.
To create a local variable within a constructor method, we use a variable definition,
as shown in the following generalized code. Notice that the definition starts with the
keyword var and, by convention, ends in a semicolon, as do all directives that do not
include a block statement. The semicolon indicates the end of the directive, much
like the period at the end of a sentence in a natural language.
class SomeClass {
public function SomeClass ( ) {
var identifier = value;
}
}
In the preceding code, identifier is the local variable’s name, and value is the value
associated with that variable. Together, the equals sign and the value are known as
the variable initializer because they determine the initial value of the variable.
20 | Chapter 1: Core Concepts
Associating a variable with a value is known as assigning, setting, or
writing the variable’s value.
When the variable initializer is omitted, ActionScript automatically assigns the variable
a default value. Default values for variables are discussed in Chapter 8.
A local variable can be used within the method or function that contains its definition
only. When the method or function finishes executing, the local variable expires
and can no longer be used by the program.
Let’s create a local variable to refer to the VirtualPet object we created earlier in the
VirtualZoo constructor. We’ll name the local variable pet, and we’ll use an initializer
to associate it with the VirtualPet object. Here’s the code:
package zoo {
public class VirtualZoo {
public function VirtualZoo ( ) {
var pet = new VirtualPet;
}
}
}
Having associated the local variable pet with a VirtualPet object, we can now use
that variable to refer to, and therefore control, that object. However, currently our
VirtualPet object can’t actually do anything because we haven’t programmed its
functionality. We’ll start to rectify that shortcoming in the next section by giving pets
the ability to have nicknames.
Instance Variables
Earlier we learned that a class describes the characteristics and behavior of a particular
type of object. In object-oriented programming terms, a “characteristic” is a specific
piece of information (i.e., value) that describes some aspect of an object—such
as its width, speed, or color. To keep track of an object’s characteristics, we use
instance variables.
An instance variable is a variable attached to a particular object. Typically, each
instance variable describes a characteristic of the object to which it is attached. For
example, an instance variable might be the identifier width associated with the value
150, describing the size of the button object in an interface. Or, an instance variable
might be the identifier shippingAddress associated with the value “34 Somewhere
St,” describing the destination of a product-order object.
Instance variables are created using variable definitions directly within class definitions,
as shown in the following generalized code
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 3:[สำเนา]
คัดลอก!
ตัวแปรท้องถิ่น
ตัวแปรท้องถิ่นจะใช้ในการติดตามข้อมูลชั่วคราวภายในขอบเขตทางกายภาพ
ของผู้สร้างวิธี เช่น วิธี วิธีการแบบคงที่หรือฟังก์ชัน .
เรายังไม่ได้เรียน เช่น วิธีการแบบคงที่หรือหน้าที่ แต่ตอนนี้
เราจะเน้นตัวแปรท้องถิ่นในวิธีการก่อสร้าง
เพื่อสร้าง ตัวแปรท้องถิ่นภายในเกี่ยวกับวิธีการเราใช้ตัวแปรนิยามทั่วไป
ดังแสดงในรหัสต่อไปนี้ สังเกตเห็นว่า คำนิยามที่เริ่มต้นด้วย
คำหลัก var และโดยการประชุมจบลงด้วยเครื่องหมายอัฒภาคที่ทำทุกแนวทางที่ไม่
รวมบล็อกข้อความ เครื่องหมายอัฒภาคแสดงสิ้นสุดของคำสั่งมาก
เหมือนช่วงท้ายของประโยคในภาษาธรรมชาติ someclass {

ชั้นsomeclass ฟังก์ชันสาธารณะ ( ) {

} ระบุ var = ค่า ;
}
ในก่อนหน้านี้รหัสระบุเป็นชื่อของตัวแปรท้องถิ่น และค่าเป็นค่า
ที่เกี่ยวข้องกับตัวแปร ด้วยกัน เสมอภาค และมูลค่าจะเรียกว่า
เออาร์ที เพราะพวกเขา กำหนด ค่าเริ่มต้นของตัวแปร |
20
ตอนที่ 1 : แนวคิดหลักมีตัวแปรที่มีค่าเป็นที่รู้จักกันเป็น การตั้งค่า หรือเขียนค่าของตัวแปร
.
เมื่อเออาร์ทีถูกตัดออก , ActionScript อัตโนมัติกําหนดตัวแปร
เริ่มต้นค่า ค่าปริยายสำหรับตัวแปรที่กล่าวถึงในบทที่ 8 .
ตัวแปรท้องถิ่นสามารถใช้ภายในวิธีการหรือฟังก์ชันที่ประกอบด้วยความหมาย
เท่านั้นเมื่อเสร็จสิ้นการวิธีการหรือฟังก์ชัน , ตัวแปรท้องถิ่นหมดอายุ
และไม่สามารถใช้โดยโปรแกรม .
ลองสร้างตัวแปรท้องถิ่นเพื่ออ้างถึง virtualpet วัตถุที่เราสร้างขึ้นก่อนหน้านี้ใน
virtualzoo ผู้สร้าง เราจะตั้งชื่อสัตว์เลี้ยงตัวแปรท้องถิ่น และเราจะใช้ initializer
ที่จะเชื่อมโยงกับ virtualpet วัตถุ นี่คือรหัส : {

ชุดสวนสัตว์สาธารณะระดับ virtualzoo {

virtualzoo ฟังก์ชันสาธารณะ ( ) { var สัตว์เลี้ยงใหม่ = virtualpet ;

} } }

มีความสัมพันธ์กับตัวแปรท้องถิ่น สัตว์เลี้ยง virtualpet วัตถุ , ตอนนี้เราสามารถใช้
ที่ตัวแปรอ้างถึงและดังนั้นจึงควบคุมวัตถุ อย่างไรก็ตาม ขณะนี้วัตถุ
virtualpet ของเราไม่ทำอะไรจริง เพราะเรายังไม่ได้ตั้งโปรแกรมของ
การทํางานเราจะเริ่มแก้ที่บกพร่องในส่วนถัดไปโดยให้สัตว์เลี้ยง
ความสามารถที่จะมีตัวแปรอินสแตนซ์

ชื่อเล่น ก่อนหน้านี้เราได้เรียนรู้ว่า ชั้นอธิบายถึงลักษณะและพฤติกรรมประเภทเฉพาะ
ของวัตถุ การเขียนโปรแกรมเชิงวัตถุในแง่เป็น " ลักษณะ " เป็นชิ้นส่วนเฉพาะ
ข้อมูล ( เช่น ค่า ) ที่อธิบายลักษณะของวัตถุเช่น
เป็นกว้าง ความเร็ว หรือสี ติดตามคุณลักษณะของวัตถุ เราใช้ตัวแปรอินสแตนซ์
.
เป็น instance variable คือตัวแปรแนบกับวัตถุที่เฉพาะเจาะจง โดยปกติแต่ละ
instance variable อธิบายลักษณะของวัตถุ ซึ่งจะแนบ สำหรับ
ตัวอย่าง ตัวอย่างตัวแปรอาจจะระบุความกว้างที่เกี่ยวข้องกับค่า
150อธิบายขนาดของปุ่มวัตถุในการติดต่อ หรือ ตัวอย่างตัวแปร
อาจจะระบุ shippingaddress เกี่ยวข้องกับค่า " 34 ที่ไหน
St , " อธิบายปลายทางของการสั่งซื้อสินค้าวัตถุ ตัวอย่างจะถูกสร้างขึ้นโดยใช้ตัวแปรตัวแปร
นิยามโดยตรงภายในชั้นเรียนความหมาย
ดังแสดงในกราฟรหัสต่อไปนี้
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2026 I Love Translation. All reserved.

E-mail: