JS: Update qhelp and added more examples.

This commit is contained in:
Napalys Klicius
2025-06-11 16:54:15 +02:00
parent 41f4236b86
commit 60e3b0c8e7
7 changed files with 73 additions and 25 deletions

View File

@@ -1,6 +1,6 @@
declare class Point {
// BAD: Using 'constructor' in an interface creates a method, not a constructor signature
interface Point {
x: number;
y: number;
constructor(x : number, y: number);
constructor(x: number, y: number); // This is just a method named "constructor"
}

View File

@@ -0,0 +1,6 @@
// BAD: Using 'new' in a class creates a method, not a constructor
class Point {
x: number;
y: number;
new(x: number, y: number) {}; // This is just a method named "new"
}

View File

@@ -0,0 +1,9 @@
// GOOD: Using 'constructor' for constructors in classes
class Point {
x: number;
y: number;
constructor(x: number, y: number) { // This is a proper constructor
this.x = x;
this.y = y;
}
}

View File

@@ -1,4 +1,6 @@
// GOOD: Using 'new' for constructor signatures in interfaces
interface Point {
x: number;
y: number;
new(x: number, y: number): Point; // This is a proper constructor signature
}

View File

@@ -0,0 +1,4 @@
// BAD: Using 'function' as a method name is confusing
interface Calculator {
function(a: number, b: number): number; // This is just a method named "function"
}

View File

@@ -0,0 +1,4 @@
// GOOD: Using descriptive method names instead of 'function'
interface Calculator {
calculate(a: number, b: number): number; // Clear, descriptive method name
}