SlideShare uma empresa Scribd logo
1 de 17
Baixar para ler offline
Typescript
natankrasney@gmail.com
1
? Typescript ‫זה‬ ‫מה‬
.‫מלמעלה‬ ‫במבט‬ Typescript ‫את‬ ‫הצגתי‬ ‫ההקדמה‬ ‫בפרק‬
‫לכתוב‬ ‫לנו‬ ‫שיאפשר‬ ‫טוב‬ ‫בסיס‬ ‫לקבל‬ ‫מנת‬ ‫על‬ Typescript ‫לתוך‬ ‫פנימה‬ ‫ניכנס‬ ‫הזה‬ ‫בפרק‬
Typescript ‫היא‬ ‫התכנות‬ ‫שפת‬ ‫בה‬ Angular 2 ‫אפליקציות‬
natankrasney@gmail.com
2
‫משתנים‬ ‫הגדרת‬
‫יותר‬ ‫בגרסאות‬ ‫הגיע‬ let ‫כי‬ ‫אם‬ javascript ‫מ‬ ‫חלק‬ ‫)שניהם‬ var ‫בעזרת‬ ‫משתנים‬ ‫להגדיר‬ ‫אפשר‬
: (‫מאוחרות‬
var num1 , num2=22 , msg = ‘hello world’ ;
: let ‫או‬
let num3 = 33;
‫הבא‬ ‫שקף‬ ‫ראה‬ - let ‫עדיף‬ ‫אבל‬
natankrasney@gmail.com
3
var ‫לעומת‬ let ‫ל‬ ‫דוגמה‬
F_var(){
for(var i=0; i< 4 ; i++){
console.log(i);
}
console.log("outside loop :" + i);
}
F_let(){
for(let i=0; i< 4 ; i++){
console.log(i);
}
console.log("outside loop :" + i);
}
constructor(){
this.F_var();
this.F_let();
}
natankrasney@gmail.com
4
‫כי‬ ‫קומפילציה‬ ‫שגיאת‬ ‫תתקבל‬
scope ‫ל‬ ‫מחוץ‬ ‫מוגדר‬ ‫לא‬ i
for ‫של‬ ‫הבלוק‬ ‫של‬
‫שמקובל‬ ‫מה‬ ‫לא‬ ‫וזה‬ 4 ‫ידפיס‬
‫מומלץ‬ ‫ולכן‬ C# ‫ב‬ ‫לדוגמא‬
var‫ב‬ ‫ולא‬ let‫ב‬ ‫להשתמש‬
‫לתוך‬ ‫לדוגמא‬ ‫הקוד‬ ‫כל‬ ‫את‬ ‫להכניס‬ ‫אפשר‬
‫בקובץ‬ AppComponent ‫המחלקה‬
app.component.ts
Type Inference ‫ב‬ ‫ושימוש‬ ‫משתנים‬
let num=1;
num = ‘some string’;
let a;
a=1;
a=true;
a=’some text’
natankrasney@gmail.com
5
‫הוא‬ num ‫כי‬ ‫קומפילציה‬ ‫שגיאת‬
‫השמה‬ ‫לעשות‬ ‫ניתן‬ ‫ולא‬ ‫מספר‬
‫אליו‬ string ‫של‬
‫ובגלל‬ num ‫משתנה‬ ‫על‬ ‫הכרזה‬
‫מסוג‬ ‫יוכרז‬ ‫הוא‬ 1 ‫של‬ ‫ההשמה‬
number
‫משתנה‬ ‫סוג‬ ‫מקבל‬
‫ערך‬ ‫כל‬ ‫כך‬ ‫ואחר‬ any
‫סוג‬ ‫מכל‬
‫משתנים‬ ‫סוגי‬
let text : string;
let num1 : number;
let flag : boolean;
let anything : any;
let ar : string[];
let ar1 : any[]=[1,2,true];
enum Color {Red , Green , Blue};
let e1 = Color.blue;
natankrasney@gmail.com
6
‫ערכים‬ ‫בעל‬
‫מאפס‬ ‫מספריים‬
1 ‫בקפיצות‬
class - ‫מחלקה‬
: ‫מלבן‬ ‫לדוגמא‬ ‫יחדיו‬ ‫שקשורות‬ ‫ופעולות‬ ‫שדות‬ ‫מקבצת‬ ‫מחלקה‬
export class Rect{
width : number;
height : number;
ComputeArea() : number
{
return this.height * this.width;
}
}
natankrasney@gmail.com
7
‫רוצים‬ ‫אם‬ export ‫ב‬ ‫משתמשים‬
‫שונה‬ ‫בקובץ‬ Rect‫ב‬ ‫להשתמש‬
‫מוגדר‬ ‫הוא‬ ‫בו‬ ‫הקובץ‬ ‫מאשר‬
‫מחלקה‬ ‫של‬ ‫אוביקט‬
let rect : Rect;
rect = new Rect();
rect.height=10;
rect.width=2;
console.log(rect.width);
console.log(rect.height);
console.log(rect.ComputeArea());
natankrasney@gmail.com
8
rect ‫משתנה‬ ‫הגדרת‬
‫והשמה‬ Rect ‫של‬ ‫אוביקט‬ ‫יצירת‬
rect ‫למשתנה‬ ‫שלו‬ ‫הכתובת‬ ‫של‬
constructor - ‫בנאי‬
export class Rect{
width : number;
height : number;
constructor( width : number , height : number){
this.height = height;
this.width = width;
}
ComputeArea() : number{
return this.height * this.width;
}}
natankrasney@gmail.com
9
‫המילה‬ ‫עם‬ ‫מוגדר‬ ‫בנאי‬
.constructor ‫השמורה‬
‫אחד‬ ‫בנאי‬ ‫רק‬ ‫מותר‬
‫במחלקה‬
access modifier - ‫גישה‬ ‫הרשאת‬
export class Rect{
private width : number;
private height : number;
constructor( width : number , height : number){
this.height = height;
this.width = width;
}
ComputeArea() : number{
return this.height * this.width;
}
}
natankrasney@gmail.com
10
: ‫גישה‬ ‫הרשאות‬ ‫שלוש‬ ‫יש‬
public , private, protected
‫בירושה‬ ‫לשימוש‬ ‫האחרון‬
‫מחוץ‬ ‫האלה‬ ‫לשדות‬ ‫לגשת‬ ‫ניתן‬ ‫לא‬
‫למחלקה‬
‫להרשאות‬ ‫המחדל‬ ‫ברירת‬
public ‫היא‬
‫בבנאי‬ ‫גישה‬ ‫הרשאת‬
export class Rect{
constructor( private width : number ,private height : number){
}
ComputeArea() : number{
return this.height * this.width;
}
}
natankrasney@gmail.com
11
‫ויוצר‬ ‫מתקמפל‬ ‫הזה‬ ‫הקוד‬
width ‫שדות‬ ‫שני‬ ‫אוטומטית‬
‫במחלקה‬ height
class properties
export class Rect{
constructor( private width : number ,private height : number){}
get Width(){
return this.width;
}
get Height(){
return this.height;
}
set Width(value){
this.width = value;
}
set Height(value){
this.height = value;
}
ComputeArea() : number{
return this.height * this.width;
}
}
natankrasney@gmail.com
12
get properties
get properties
properties ‫ב‬ ‫לשימוש‬ ‫דוגמה‬
let rect : Rect;
rect = new Rect(10,20);
console.log(rect.Height);
console.log(rect.Width);
rect.Height = 100;
rect.Width = 3;
console.log(rect.ComputeArea());
natankrasney@gmail.com
13
get property - ‫ב‬ ‫שימוש‬
getter
set property - ‫ב‬ ‫שימוש‬
setter
Arrow Functions
(javascript‫מ‬ ‫מגיע‬ ‫)זה‬ arrow function ‫של‬ ‫כללי‬ ‫מבנה‬
(arguments) => return value { statements}
let f = (msg : string) =>
{
console.log(msg);
}
f("hello");
natankrasney@gmail.com
14
lambda ‫נקרא‬ ‫זה‬ C# ‫ב‬
‫אחת‬ ‫שורה‬ ‫רק‬ ‫יש‬ ‫אם‬ .expression
‫הבלוק‬ ‫סימון‬ ‫את‬ ‫להוריד‬ ‫אפשר‬ ‫אז‬
{ } ‫קרי‬
- ‫שם‬ ‫ללא‬ ‫פונקציה‬ ‫כאן‬ ‫יצרנו‬
anonymous function
Interface
let person :IPerson = {
Name:"Tom",
Age:32,
GetSigniture: ():string =>{return
person.Name+person.Age}
}
console.log(person.Name);
console.log(person.Age);
console.log(person.GetSigniture());
natankrasney@gmail.com
15
export interface IPerson {
Name:string,
Age:number,
GetSigniture: ()=>string
}
‫שאוביקט‬ ‫חוזה‬ ‫הוא‬ Interface
‫לקיים‬ ‫צריך‬ ‫כזה‬ ‫שהוא‬ ‫שטוען‬
‫מוגדר‬ ‫כאן‬ IPerson
‫לדוגמא‬ ‫בקובץ‬
iperson.ts
interface ‫ב‬ ‫שימוש‬
‫כלשהיא‬ ‫בפונקציה‬
Modules
‫מחוץ‬ ‫הזו‬ ‫במחלקה‬ ‫להשתמש‬ ‫שניתן‬ ‫מנת‬ ‫על‬ .rect.ts ‫בקובץ‬ Rect ‫המחלקה‬ ‫את‬ ‫שיצרנו‬ ‫נניח‬
: ‫דברים‬ ‫שני‬ ‫לעשות‬ ‫יש‬ ‫הזה‬ ‫לקובץ‬
●export ‫עם‬ ‫מוגדרת‬ ‫שהמחלקה‬ ‫לוודא‬
export class Rect{
}
●‫לדוגמא‬ ‫במחלקה‬ ‫להשתמש‬ ‫רוצים‬ ‫בו‬ ‫בקובץ‬ import ‫לעשות‬
import { Rect } from './rect';
natankrasney@gmail.com
16
typescript ‫ומבחינת‬ ‫הקובץ‬ ‫של‬ path‫ל‬ ‫מתייחס‬
‫נמצא‬ rect.ts ‫הקובץ‬ ‫זה‬ ‫במקרה‬ .module ‫זהו‬
import ‫שעושה‬ ‫הקובץ‬ ‫נמצא‬ ‫בה‬ ‫ספריה‬ ‫באותה‬
modules ‫של‬ ‫סכמטי‬ ‫תאור‬
natankrasney@gmail.com
17
File 1
File 2
Module Module
File 3
Module
export export import import

Mais conteúdo relacionado

Destaque

TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type scriptRemo Jansen
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponLaurent Duveau
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type scriptDmitrii Stoian
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21MoscowJS
 
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)Ontico
 
TypeScript Seminar
TypeScript SeminarTypeScript Seminar
TypeScript SeminarHaim Michael
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScriptOffirmo
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
 
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesTypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesMicael Gallego
 
Typescript + Graphql = <3
Typescript + Graphql = <3Typescript + Graphql = <3
Typescript + Graphql = <3felixbillon
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 

Destaque (19)

TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Typescript
TypescriptTypescript
Typescript
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
TypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret WeaponTypeScript: Angular's Secret Weapon
TypeScript: Angular's Secret Weapon
 
002. Introducere in type script
002. Introducere in type script002. Introducere in type script
002. Introducere in type script
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 
TypeScript
TypeScriptTypeScript
TypeScript
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
«Typescript: кому нужна строгая типизация?», Григорий Петров, MoscowJS 21
 
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
TypeScript: особенности разработки / Александр Майоров (Tutu.ru)
 
TypeScript Seminar
TypeScript SeminarTypeScript Seminar
TypeScript Seminar
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
 
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristesTypeScript: Un lenguaje aburrido para programadores torpes y tristes
TypeScript: Un lenguaje aburrido para programadores torpes y tristes
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Typescript + Graphql = <3
Typescript + Graphql = <3Typescript + Graphql = <3
Typescript + Graphql = <3
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
TypeScriptで快適javascript
TypeScriptで快適javascriptTypeScriptで快適javascript
TypeScriptで快適javascript
 

Semelhante a Angular 2 - Typescript

רשימת פונקציות שימושיות c++
 רשימת פונקציות שימושיות  c++  רשימת פונקציות שימושיות  c++
רשימת פונקציות שימושיות c++ Eitan Keren
 
בדרך לפולימורפיזם - העמסת ועקיפת פונקציות
בדרך לפולימורפיזם - העמסת ועקיפת פונקציותבדרך לפולימורפיזם - העמסת ועקיפת פונקציות
בדרך לפולימורפיזם - העמסת ועקיפת פונקציותמורן אלקובי
 

Semelhante a Angular 2 - Typescript (6)

רשימת פונקציות שימושיות c++
 רשימת פונקציות שימושיות  c++  רשימת פונקציות שימושיות  c++
רשימת פונקציות שימושיות c++
 
javascript
javascriptjavascript
javascript
 
react-he.pdf
react-he.pdfreact-he.pdf
react-he.pdf
 
Angular 2 jump start
Angular 2 jump startAngular 2 jump start
Angular 2 jump start
 
בדרך לפולימורפיזם - העמסת ועקיפת פונקציות
בדרך לפולימורפיזם - העמסת ועקיפת פונקציותבדרך לפולימורפיזם - העמסת ועקיפת פונקציות
בדרך לפולימורפיזם - העמסת ועקיפת פונקציות
 
ADO.Net
ADO.NetADO.Net
ADO.Net
 

Mais de Nathan Krasney

Mais de Nathan Krasney (16)

Introduction to Semantic ui-react
Introduction to Semantic ui-reactIntroduction to Semantic ui-react
Introduction to Semantic ui-react
 
React introduction
React introductionReact introduction
React introduction
 
Angular 2 introduction
Angular 2 introductionAngular 2 introduction
Angular 2 introduction
 
Angular 2 binding
Angular 2  bindingAngular 2  binding
Angular 2 binding
 
JQuery
JQueryJQuery
JQuery
 
ASP.net Security
ASP.net SecurityASP.net Security
ASP.net Security
 
ASP.net Web Pages
ASP.net Web PagesASP.net Web Pages
ASP.net Web Pages
 
ASP.net MVC
ASP.net MVCASP.net MVC
ASP.net MVC
 
CSS
CSSCSS
CSS
 
Javascript with json
Javascript with jsonJavascript with json
Javascript with json
 
Javascript ajax
Javascript ajaxJavascript ajax
Javascript ajax
 
HTML5
HTML5 HTML5
HTML5
 
HTML
HTML HTML
HTML
 
קורס אנדרואיד
קורס אנדרואידקורס אנדרואיד
קורס אנדרואיד
 
Lessons learned from 6 month project with india based software house
Lessons learned from 6 month project with india based software houseLessons learned from 6 month project with india based software house
Lessons learned from 6 month project with india based software house
 
Introduction to big data
Introduction to big data Introduction to big data
Introduction to big data
 

Angular 2 - Typescript

  • 2. ? Typescript ‫זה‬ ‫מה‬ .‫מלמעלה‬ ‫במבט‬ Typescript ‫את‬ ‫הצגתי‬ ‫ההקדמה‬ ‫בפרק‬ ‫לכתוב‬ ‫לנו‬ ‫שיאפשר‬ ‫טוב‬ ‫בסיס‬ ‫לקבל‬ ‫מנת‬ ‫על‬ Typescript ‫לתוך‬ ‫פנימה‬ ‫ניכנס‬ ‫הזה‬ ‫בפרק‬ Typescript ‫היא‬ ‫התכנות‬ ‫שפת‬ ‫בה‬ Angular 2 ‫אפליקציות‬ natankrasney@gmail.com 2
  • 3. ‫משתנים‬ ‫הגדרת‬ ‫יותר‬ ‫בגרסאות‬ ‫הגיע‬ let ‫כי‬ ‫אם‬ javascript ‫מ‬ ‫חלק‬ ‫)שניהם‬ var ‫בעזרת‬ ‫משתנים‬ ‫להגדיר‬ ‫אפשר‬ : (‫מאוחרות‬ var num1 , num2=22 , msg = ‘hello world’ ; : let ‫או‬ let num3 = 33; ‫הבא‬ ‫שקף‬ ‫ראה‬ - let ‫עדיף‬ ‫אבל‬ natankrasney@gmail.com 3
  • 4. var ‫לעומת‬ let ‫ל‬ ‫דוגמה‬ F_var(){ for(var i=0; i< 4 ; i++){ console.log(i); } console.log("outside loop :" + i); } F_let(){ for(let i=0; i< 4 ; i++){ console.log(i); } console.log("outside loop :" + i); } constructor(){ this.F_var(); this.F_let(); } natankrasney@gmail.com 4 ‫כי‬ ‫קומפילציה‬ ‫שגיאת‬ ‫תתקבל‬ scope ‫ל‬ ‫מחוץ‬ ‫מוגדר‬ ‫לא‬ i for ‫של‬ ‫הבלוק‬ ‫של‬ ‫שמקובל‬ ‫מה‬ ‫לא‬ ‫וזה‬ 4 ‫ידפיס‬ ‫מומלץ‬ ‫ולכן‬ C# ‫ב‬ ‫לדוגמא‬ var‫ב‬ ‫ולא‬ let‫ב‬ ‫להשתמש‬ ‫לתוך‬ ‫לדוגמא‬ ‫הקוד‬ ‫כל‬ ‫את‬ ‫להכניס‬ ‫אפשר‬ ‫בקובץ‬ AppComponent ‫המחלקה‬ app.component.ts
  • 5. Type Inference ‫ב‬ ‫ושימוש‬ ‫משתנים‬ let num=1; num = ‘some string’; let a; a=1; a=true; a=’some text’ natankrasney@gmail.com 5 ‫הוא‬ num ‫כי‬ ‫קומפילציה‬ ‫שגיאת‬ ‫השמה‬ ‫לעשות‬ ‫ניתן‬ ‫ולא‬ ‫מספר‬ ‫אליו‬ string ‫של‬ ‫ובגלל‬ num ‫משתנה‬ ‫על‬ ‫הכרזה‬ ‫מסוג‬ ‫יוכרז‬ ‫הוא‬ 1 ‫של‬ ‫ההשמה‬ number ‫משתנה‬ ‫סוג‬ ‫מקבל‬ ‫ערך‬ ‫כל‬ ‫כך‬ ‫ואחר‬ any ‫סוג‬ ‫מכל‬
  • 6. ‫משתנים‬ ‫סוגי‬ let text : string; let num1 : number; let flag : boolean; let anything : any; let ar : string[]; let ar1 : any[]=[1,2,true]; enum Color {Red , Green , Blue}; let e1 = Color.blue; natankrasney@gmail.com 6 ‫ערכים‬ ‫בעל‬ ‫מאפס‬ ‫מספריים‬ 1 ‫בקפיצות‬
  • 7. class - ‫מחלקה‬ : ‫מלבן‬ ‫לדוגמא‬ ‫יחדיו‬ ‫שקשורות‬ ‫ופעולות‬ ‫שדות‬ ‫מקבצת‬ ‫מחלקה‬ export class Rect{ width : number; height : number; ComputeArea() : number { return this.height * this.width; } } natankrasney@gmail.com 7 ‫רוצים‬ ‫אם‬ export ‫ב‬ ‫משתמשים‬ ‫שונה‬ ‫בקובץ‬ Rect‫ב‬ ‫להשתמש‬ ‫מוגדר‬ ‫הוא‬ ‫בו‬ ‫הקובץ‬ ‫מאשר‬
  • 8. ‫מחלקה‬ ‫של‬ ‫אוביקט‬ let rect : Rect; rect = new Rect(); rect.height=10; rect.width=2; console.log(rect.width); console.log(rect.height); console.log(rect.ComputeArea()); natankrasney@gmail.com 8 rect ‫משתנה‬ ‫הגדרת‬ ‫והשמה‬ Rect ‫של‬ ‫אוביקט‬ ‫יצירת‬ rect ‫למשתנה‬ ‫שלו‬ ‫הכתובת‬ ‫של‬
  • 9. constructor - ‫בנאי‬ export class Rect{ width : number; height : number; constructor( width : number , height : number){ this.height = height; this.width = width; } ComputeArea() : number{ return this.height * this.width; }} natankrasney@gmail.com 9 ‫המילה‬ ‫עם‬ ‫מוגדר‬ ‫בנאי‬ .constructor ‫השמורה‬ ‫אחד‬ ‫בנאי‬ ‫רק‬ ‫מותר‬ ‫במחלקה‬
  • 10. access modifier - ‫גישה‬ ‫הרשאת‬ export class Rect{ private width : number; private height : number; constructor( width : number , height : number){ this.height = height; this.width = width; } ComputeArea() : number{ return this.height * this.width; } } natankrasney@gmail.com 10 : ‫גישה‬ ‫הרשאות‬ ‫שלוש‬ ‫יש‬ public , private, protected ‫בירושה‬ ‫לשימוש‬ ‫האחרון‬ ‫מחוץ‬ ‫האלה‬ ‫לשדות‬ ‫לגשת‬ ‫ניתן‬ ‫לא‬ ‫למחלקה‬ ‫להרשאות‬ ‫המחדל‬ ‫ברירת‬ public ‫היא‬
  • 11. ‫בבנאי‬ ‫גישה‬ ‫הרשאת‬ export class Rect{ constructor( private width : number ,private height : number){ } ComputeArea() : number{ return this.height * this.width; } } natankrasney@gmail.com 11 ‫ויוצר‬ ‫מתקמפל‬ ‫הזה‬ ‫הקוד‬ width ‫שדות‬ ‫שני‬ ‫אוטומטית‬ ‫במחלקה‬ height
  • 12. class properties export class Rect{ constructor( private width : number ,private height : number){} get Width(){ return this.width; } get Height(){ return this.height; } set Width(value){ this.width = value; } set Height(value){ this.height = value; } ComputeArea() : number{ return this.height * this.width; } } natankrasney@gmail.com 12 get properties get properties
  • 13. properties ‫ב‬ ‫לשימוש‬ ‫דוגמה‬ let rect : Rect; rect = new Rect(10,20); console.log(rect.Height); console.log(rect.Width); rect.Height = 100; rect.Width = 3; console.log(rect.ComputeArea()); natankrasney@gmail.com 13 get property - ‫ב‬ ‫שימוש‬ getter set property - ‫ב‬ ‫שימוש‬ setter
  • 14. Arrow Functions (javascript‫מ‬ ‫מגיע‬ ‫)זה‬ arrow function ‫של‬ ‫כללי‬ ‫מבנה‬ (arguments) => return value { statements} let f = (msg : string) => { console.log(msg); } f("hello"); natankrasney@gmail.com 14 lambda ‫נקרא‬ ‫זה‬ C# ‫ב‬ ‫אחת‬ ‫שורה‬ ‫רק‬ ‫יש‬ ‫אם‬ .expression ‫הבלוק‬ ‫סימון‬ ‫את‬ ‫להוריד‬ ‫אפשר‬ ‫אז‬ { } ‫קרי‬ - ‫שם‬ ‫ללא‬ ‫פונקציה‬ ‫כאן‬ ‫יצרנו‬ anonymous function
  • 15. Interface let person :IPerson = { Name:"Tom", Age:32, GetSigniture: ():string =>{return person.Name+person.Age} } console.log(person.Name); console.log(person.Age); console.log(person.GetSigniture()); natankrasney@gmail.com 15 export interface IPerson { Name:string, Age:number, GetSigniture: ()=>string } ‫שאוביקט‬ ‫חוזה‬ ‫הוא‬ Interface ‫לקיים‬ ‫צריך‬ ‫כזה‬ ‫שהוא‬ ‫שטוען‬ ‫מוגדר‬ ‫כאן‬ IPerson ‫לדוגמא‬ ‫בקובץ‬ iperson.ts interface ‫ב‬ ‫שימוש‬ ‫כלשהיא‬ ‫בפונקציה‬
  • 16. Modules ‫מחוץ‬ ‫הזו‬ ‫במחלקה‬ ‫להשתמש‬ ‫שניתן‬ ‫מנת‬ ‫על‬ .rect.ts ‫בקובץ‬ Rect ‫המחלקה‬ ‫את‬ ‫שיצרנו‬ ‫נניח‬ : ‫דברים‬ ‫שני‬ ‫לעשות‬ ‫יש‬ ‫הזה‬ ‫לקובץ‬ ●export ‫עם‬ ‫מוגדרת‬ ‫שהמחלקה‬ ‫לוודא‬ export class Rect{ } ●‫לדוגמא‬ ‫במחלקה‬ ‫להשתמש‬ ‫רוצים‬ ‫בו‬ ‫בקובץ‬ import ‫לעשות‬ import { Rect } from './rect'; natankrasney@gmail.com 16 typescript ‫ומבחינת‬ ‫הקובץ‬ ‫של‬ path‫ל‬ ‫מתייחס‬ ‫נמצא‬ rect.ts ‫הקובץ‬ ‫זה‬ ‫במקרה‬ .module ‫זהו‬ import ‫שעושה‬ ‫הקובץ‬ ‫נמצא‬ ‫בה‬ ‫ספריה‬ ‫באותה‬
  • 17. modules ‫של‬ ‫סכמטי‬ ‫תאור‬ natankrasney@gmail.com 17 File 1 File 2 Module Module File 3 Module export export import import