constbook1=newBook("The Great Gatsby",20,"11/04/1955","Tom Joe");// console.log(book1);// console.log(book1.promo());constaddToShelter=(obj:Book)=>{console.log("ADDED TO SHELTER",obj);}// addToShelter(new Book("Nana", 5, "12/07/1905", "Zola",// ["Roman Historique", "Roman"]))letonlyBook:Book[]=[];onlyBook.push(newBook("Nana",5,"12/07/1905","Zola",["Roman Historique","Roman"]))console.log(onlyBook);
Les champs
classBook{privatebookID=88readonlylibraryName="The Book Shelf"constructor(publictitle:string,publicprice:number,publicdateOfParution:string,publicauthor:string,publictheme?:string[]){}promo(){console.log("ID",this.bookID);console.log("NAME",this.libraryName);// this.libraryName = 500returnthis.price*0.5;}}
constbook1=newBook("The Great Gatsby",20,"11/04/1955","Tom Joe");console.log(book1);console.log(book1.promo());console.log(book1.libraryName);constaddToShelter=(obj:Book)=>{console.log("ADDED TO SHELTER",obj);}// addToShelter(new Book("Nana", 5, "12/07/1905", "Zola",// ["Roman Historique", "Roman"]))letonlyBook:Book[]=[];onlyBook.push(newBook("Nana",5,"12/07/1905","Zola",["Roman Historique","Roman"]))// console.log(onlyBook);
// Syntaxe sans raccourci classBook{title:string;price:number;dateOfParution:string;author:string;theme?:string[];privatebookID=88readonlylibraryName="The Book Shelf"constructor(t:string,p:number,dop:string,a:string,th?:string[]){this.title=t;this.price=p;this.dateOfParution=dop;this.author=a;this.theme=th;}promo(){console.log("ID",this.bookID);console.log("NAME",this.libraryName);this.libraryName=500returnthis.price*0.5;}}