class Point {
constructor(x = 0, y = 0) {
this.x = x;
this.y = y;
}
toString() {
return `(${this.x}, ${this.y})`;
}
}
class NamedPoint extends Point {
constructor(name = "defaultName", x = 0, y = 0) {
super(x, y)
this.name = name;
}
toString() {
return `NamedPoint: ${this.name} ${super.toString()}`
}
}
let nums = [1,2,3,4,5,6,7];
let odds = nums.filter(i => i%2);
// [1,3,5,7]
let evens = nums.filter(i => i%2 === 0);
// [2,4,6]
let forEachAdd = (arr, add) => arr.map(i => i+add)
forEachAdd(num, 2) // [3,4,5,6,7,8,9]
forEachAdd(num, 4) // [5,6,7,8,9,10,11]
interface IPoint {
x: number;
y: number
}
class Point implements IPoint {
constructor(
public x: number = 0,
public y: number = 0
) {}
toString() {
return `(${this.x}, ${this.y})`;
}
}
class NamedPoint extends Point {
constructor(
public name: string = "defaultName",
public x: number = 0,
public y: number = 0
) {
super(x, y)
}
toString() {
return `NamedPoint: ${this.name} ${super.toString()}`
}
}
Créer un projet à partir de zéro !