Seluruh kendaraan pasti butuh yang namanya perawatan bukan? Jika iya, tentu kita perlu membuat method repair untuk memperbaiki kendaraan tersebut. 
Dalam analogi dunia nyata, ketika kendaraan mengalami kerusakan maka kendaraan tersebut akan diperbaiki di bengkel (factory), sehingga kita perlu membuat class baru yang berperan sebagai factory, sebutlah class tersebut VehicleFactory. Di dalam kelas VehicleFactory terdapat satu method repair() yang dapat menerima banyak kendaraan sebagai parameternya.

  1. class Vehicle {

  2.   constructor(licensePlate, manufacture) {

  3.       this.licensePlate = licensePlate;

  4.       this.manufacture = manufacture;

  5.       this.engineActive = false;

  6.   }

  7.    /*

  8.   kode lainnya

  9.   */

  10. }

  11.  

  12. /* kode lainnya dalam pembuatan class Car, 

  13. Motorcycle, dsb. */

  14.  

  15.  

  16. class VehicleFactory {

  17.  repair(vehicles) {

  18.     vehicles.forEach(vehicle => {

  19.       console.log(`Kendaraan ${vehicle.licensePlate} sedang melakukan perawatan`)

  20.     })

  21.   }

  22. }


Untuk mengakses method dari class, sejauh ini kita perlu membuat instance dari classnya terlebih dahulu. Sehingga untuk memanggil repair(), kita perlu membuat instance dari class VehicleFactory

  1. const johnCar = new Car("H121S", "Honda", 4);

  2. const tomMotor = new Motorcycle("GF121J", "Yamaha", 2);

  3. const dimasCar = new Car("TA1408K", "Tesla", 4);

  4.  

  5. /* Membuat instance untuk memanggil fungsi repair */

  6. const vehicleFactory = new VehicleFactory();

  7. vehicleFactory.repair([johnCar, tomMotor, dimasCar]);

  8.  

  9. /* output:

  10. Kendaraan H121S sedang melakukan perawatan

  11. Kendaraan GF121J sedang melakukan perawatan

  12. Kendaraan TA1408K sedang melakukan perawatan

  13. */


Kode tersebut berjalan sesuai harapan namun tidak efektif. Mengapa? Karena kita perlu membuat instance untuk sekedar memanggil satu fungsi dari class-nya tersebut. Membuat instance adalah membuat sebuah objek baru yang terbentuk melalui blueprint sehingga membutuhkan memori ekstra. Jika kita dapat mengakses method tersebut tanpa melalui instance mengapa tidak? Pada kasus inilah kita membutuhkan sebuah static method. Static method merupakan method yang tidak dapat dipanggil oleh instance dari class, namun dapat dipanggil melalui class-nya sendiri.
Pada ES6 class kita dapat membuat static method dengan menambahkan keyword static sebelum deklarasi method-nya:

  1. class Vehicle {

  2.   constructor(licensePlate, manufacture) {

  3.       this.licensePlate = licensePlate;

  4.       this.manufacture = manufacture;

  5.       this.engineActive = false;

  6.   }

  7.    /*

  8.   kode lainnya

  9.   */

  10. }

  11.  

  12. /* kode lainnya dalam pembuatan class Car, 

  13. Motorcycle, dsb. */

  14.  

  15. class VehicleFactory {

  16.  static repair(vehicles) {

  17.     vehicles.forEach(vehicle => {

  18.       console.log(`Kendaraan ${vehicle.licensePlate} sedang melakukan perawatan`)

  19.     })

  20.   }

  21. }


Kemudian untuk memanggil methodnya kita bisa panggil melalui class Vehicle kemudian repair().
Seluruh kendaraan pasti butuh yang namanya perawatan bukan? Jika iya, tentu kita perlu membuat method repair untuk memperbaiki kendaraan tersebut. Dalam analogi dunia nyata, ketika kendaraan mengalami kerusakan maka kendaraan tersebut akan diperbaiki di bengkel (factory), sehingga kita perlu membuat class baru yang berperan sebagai factory, sebutlah class tersebut VehicleFactory. Di dalam kelas VehicleFactory terdapat satu method repair() yang dapat menerima banyak kendaraan sebagai parameternya. 

  1. class Vehicle {

  2.   constructor(licensePlate, manufacture) {

  3.       this.licensePlate = licensePlate;

  4.       this.manufacture = manufacture;

  5.       this.engineActive = false;

  6.   }

  7.    /*

  8.   kode lainnya

  9.   */

  10. }

  11.  

  12. /* kode lainnya dalam pembuatan class Car, 

  13. Motorcycle, dsb. */

  14.  

  15.  

  16. class VehicleFactory {

  17.  repair(vehicles) {

  18.     vehicles.forEach(vehicle => {

  19.       console.log(`Kendaraan ${vehicle.licensePlate} sedang melakukan perawatan`)

  20.     })

  21.   }

  22. }


Untuk mengakses method dari class, sejauh ini kita perlu membuat instance dari classnya terlebih dahulu. Sehingga untuk memanggil repair(), kita perlu membuat instance dari class VehicleFactory

  1. const johnCar = new Car("H121S", "Honda", 4);

  2. const tomMotor = new Motorcycle("GF121J", "Yamaha", 2);

  3. const dimasCar = new Car("TA1408K", "Tesla", 4);

  4.  

  5. /* Membuat instance untuk memanggil fungsi repair */

  6. const vehicleFactory = new VehicleFactory();

  7. vehicleFactory.repair([johnCar, tomMotor, dimasCar]);

  8.  

  9. /* output:

  10. Kendaraan H121S sedang melakukan perawatan

  11. Kendaraan GF121J sedang melakukan perawatan

  12. Kendaraan TA1408K sedang melakukan perawatan

  13. */


Kode tersebut berjalan sesuai harapan namun tidak efektif. Mengapa? Karena kita perlu membuat instance untuk sekedar memanggil satu fungsi dari class-nya tersebut. Membuat instance adalah membuat sebuah objek baru yang terbentuk melalui blueprint sehingga membutuhkan memori ekstra. Jika kita dapat mengakses method tersebut tanpa melalui instance mengapa tidak? Pada kasus inilah kita membutuhkan sebuah static method. Static method merupakan method yang tidak dapat dipanggil oleh instance dari class, namun dapat dipanggil melalui class-nya sendiri.
Pada ES6 class kita dapat membuat static method dengan menambahkan keyword static sebelum deklarasi method-nya:

  1. class Vehicle {

  2.   constructor(licensePlate, manufacture) {

  3.       this.licensePlate = licensePlate;

  4.       this.manufacture = manufacture;

  5.       this.engineActive = false;

  6.   }

  7.    /*

  8.   kode lainnya

  9.   */

  10. }

  11.  

  12. /* kode lainnya dalam pembuatan class Car, 

  13. Motorcycle, dsb. */

  14.  

  15. class VehicleFactory {

  16.  static repair(vehicles) {

  17.     vehicles.forEach(vehicle => {

  18.       console.log(`Kendaraan ${vehicle.licensePlate} sedang melakukan perawatan`)

  19.     })

  20.   }

  21. }


Kemudian untuk memanggil methodnya kita bisa panggil melalui class Vehicle kemudian repair().
No image
Bookmark

Static Method didalam Class Javascript

Type:
Genre:
Status:
Country:
Keywords: Watch online Static Method didalam Class Javascript bahasa Indonesia, Streaming anime Static Method didalam Class Javascript sub indo, Mau nonton anime terbaik dengan subtitle Indonesia? Streaming anime Jepang dari anime Static Method didalam Class Javascript, website streaming anime subtitle indonesia dan nonton anime indo update setiap hari, TV Static Method didalam Class Javascript, Terbaru Terupdate dan Terlengkap dengan Kualitas 1080p, 720p. 480p, 360p Anime Sub Indo.

Comments

Comment Report Rule
Show Comments
9Anime Comment Policies & Guidelines
  1. Spoiling Content

    Definition

    “Anime Comment” is a spoiler-free section and is usually used for a general discussion about anime without spoiling any content.

    “Episode Comment” may contain spoilers for current or previous episodes. Contents from manga or future episodes are considered as spoilers.

    Hiding spoilers with spoiler tags is not allowed either.

    Consequences

    Minor Spoiler:-

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

    Major Spoiler:-

    1st Offense: Permanent Ban

  2. Diversion From Topic

    Definition

    The comment section should be about the anime on hand. Although references from other anime may be used, the core topic of the comments should be about the anime at hand.

    This rule also applies on advertising other streaming websites which results in an instant ban.

    This rule also applies to spam, posting comments like “first”, “second”, etc. are considered spam.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  3. Flame War

    Definition

    Exchange of angry or abusive messages between the comments. Any form of insulting is also considered as flame war.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  4. Posting Harmful Link

    Definition

    Post of hyperlinks for websites that may contain viruses or may harm your PC or device.

    Consequences

    1st Offense: Permanent Ban + Deletion of All Comments

  5. Posting NSFW Content

    Definition

    Posting contents that are not safe for work, such as pornographic images or video, ecchi anime, hentai, etc.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  6. Inappropriate Profile Picture

    Definition

    Using a profile picture that is not safe for work. Although minor ecchi or fanservice is acceptable.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  7. Use of Common Sense

    Definition

    If you think that you’ll get in trouble for what you’re about to do, don’t do it.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  8. Upvote Abusing

    Definition

    Creating multiple alternative accounts to upvote your own comments.

    Consequences

    1st Offense: Permanent Ban on All Accounts + Deletion of All Comments

  9. Downvote Abusing

    Definition

    Targeting a user and downvoting all his comments, or creating multiple accounts to downvote one or more comments.

    Consequences

    1st Offense: Permanent Ban on All Accounts

  10. Swearing

    Definition

    Swearing is fine, as long as it’s not directed towards anyone, even as a joke. It may be misinterpreted by a moderator.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

  11. Moderator Verdict

    Definition

    A moderator’s verdict is final and arguing with them will only cause further punishment. If you have a complaint against a staff member, or wish to file a ban appeal, go to the 9Anime Discord Server and post your issue in the #disqus-appeals channel.

    Consequences

    1st Offense: Warning + Temporary Ban (Ranging 1 day to 3 days)

    2nd Offense Within 30 Days of 1st Offense: Permanent Ban

Think you have been unfairly warned or banned?

If you believe that you’ve been unfairly banned or if you have a complaint against one or more Disqus Staff Members, you may post an appeal or complaint on 9Anime Discord Server.

STEPS

  1. Join 9Anime Discord Server: https://discord.gg/xxxxxxx
  2. Read the #rules channel and follow instructions. (Optional, but highly recommended)
  3. Head towards #disqus-appeals channel.
  4. Use the appropriate template to appeal a ban or file a complaint.