ValueScript만의 부작용 방지 전략(TL;DR)
Feb 23 2023
ValueScript는 기본적으로 부작용이 없는 TypeScript입니다. 구문은 동일합니다(말 그대로 수정되지 않은 TypeScript 파서를 사용함).
ValueScript는 기본적으로 부작용이 없는 TypeScript입니다.
구문은 동일합니다(말 그대로 수정되지 않은 TypeScript 파서를 사용함). 동작은 거의 동일하지만 부작용을 방지하기 위한 다음 세 가지 차이점이 있습니다.
첫째, ValueScript는 값 의미 체계를 사용합니다.
const origin = { x: 0, y: 0 };
let pos = origin; // Assigns the *value*, not the same identity
pos.y += 10; // Move up 10 units
return origin;
// ~~~~~~ JavaScript: (0, 10)
// ~~~~~~ ValueScript: (0, 0)
let nextId = 1;
// ~~~~~~ `nextId` should be declared using `const` because it is
// implicitly const due to capture
function generateId() {
const result = nextId;
nextId++;
// ~~~~~~ Cannot mutate captured variable `nextId`
return result;
}
class Point {
constructor(
public x: number,
public y: number,
) {}
rotate(angle: number) {
const prev = this;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
this.x = cos * prev.x - sin * prev.y;
// prev.x is not affected by the previous line (see first point)
// vehicle.pos is also not affected yet, but it will be (this point)
this.y = sin * prev.x + cos * prev.y;
}
}
const vehicle = {
pos: new Point(3, 5);
};
// Inside `rotate`, `this` changes to (-5, 3)
// Upon return, that value is assigned to vehicle.pos
vehicle.pos.rotate(Math.PI / 2);
읽지 않는 것에 대해 마음이 바뀌었다면 여기 전체 기사가 있습니다 :).

![연결된 목록이란 무엇입니까? [1 부]](https://post.nghiatu.com/assets/images/m/max/724/1*Xokk6XOjWyIGCBujkJsCzQ.jpeg)



































