This commit is contained in:
miqlangelo 2025-05-06 13:54:41 +02:00
parent ab6258648b
commit fabd565ebe

View File

@ -0,0 +1,77 @@
const add = (a: number, b: number) => {
return a + b;
};
console.log(add(2, 3));
const multiply = (a: number, b: number): number => a * b;
console.log(multiply(3, 4));
class Counter {
count = 0;
// increment() {
// setTimeout(function () {
// console.log(this.count);
// }, 1000)
// }
increment() {
setTimeout(() => {
console.log(this.count);
}, 200);
}
}
const counter = new Counter();
counter.increment();
function normalFunction() {
console.log(arguments);
}
normalFunction('a', 1, 3);
const arrowFunction = (...args: any[]) => {
console.log(args);
};
arrowFunction('a', 33, true);
class Person {
name = 'Alice';
sayHello = () => {
console.log(`Hallo, mein Name ist ${this.name}`);
};
}
const person = new Person();
const greet = person.sayHello;
greet();
class Utils {
static normalFunction(value: string) {
return value.toUpperCase();
}
static arrowFunction = (value: string) => value.toLocaleLowerCase();
}
console.log(Utils.normalFunction('Hallo'));
console.log(Utils.arrowFunction('Hallo'));
class NormalMethodExample {
method() {
return 'Ich bin eine normale Methode.';
}
}
class ArrowFunctionExample {
method = () => 'Ich bin eine Arrow Function';
}
const obj1 = new NormalMethodExample();
const obj2 = new ArrowFunctionExample();
console.log(obj1.method === new NormalMethodExample().method);
console.log(obj2.method === new ArrowFunctionExample().method);