In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use the class class of TypeScript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Class class
Class is a concept in the programming of object-oriented language and the foundation of object-oriented programming.
A class is a template for creating objects and an abstraction of a class of things with common characteristics in real life.
The interior of the class encapsulates properties and methods for manipulating its own members
Example
Treat each dog as an object, and its attributes include breed, color, methods (behavior), licking, barking, and eating.
Class Dog {breed: string; color: string; lick (): void {console.log (`I still think our real purpose as a licking dog is to have a true love, not to be a true licking dog for love's sake. Although to lick the dog, but have the ambition of Wolf Warriors, lick one person for small love, lick a hundred people for great love, the so-called great love boundless. So licking is not shameful!);} eat (): void {console.log (`licking a dog is not worthy to eat! `);} bark (): void {console.log);}} / create an instance const dog = new Dog (); dog.breed=' licks' dog.color=' gold'; / / calls the instance's method dog.lick () constructor
Defined with the keyword constructor, unfortunately, multiple constructor implementations are not allowed
Class Dog {breed: string; color: string; / / constructor () {/ /}; / / constructor (breed: string) {/ / this.breed = breed; / /} constructor (breed: string, color: string) {this.breed = breed; this.color = color;}} / / create instance const dog = new Dog (','); inherit
The subclass Dog inherits the parent class Animal through the extends keyword and creates an instance of dog that can call the run () method.
Class Animal {run (distance: number) {console.log (`run ${distance} m`)}} class Dog extends Animal {breed: string; color: string Lick (): void {console.log ('I still think our real purpose as a licking dog is to have a true love, not to be a true licking dog for love. Although we want to lick a dog, we have the ambition of Wolf Warriors, licking one person for small love, licking a hundred people for great love, the so-called great love without limits. So licking is not shameful!);} eat (): void {console.log (`licking a dog is not worthy to eat! `);} bark (): void {console.log);}} / create an instance const dog = new Dog (); dog.breed = 'lick' dog.color = 'gold'; / / call the instance's method dog.run (100); that's all for "how to use the class class of TypeScript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.