Skip to content

Commit

Permalink
Remove prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
qluana7 committed Sep 30, 2021
1 parent de4abef commit 2928f0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/entities/hangul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { disassemble } from "../assemblers/disassemble.ts"
import { InteractLists } from "./interactList.ts"
import { HangulBuilder } from "./hangulBuilder.ts"

function insert(origin: string, ind: number, value: string): string {
return [origin.slice(0, ind), value, origin.slice(ind)].join('');
}

/**
* Specific string class which provides function for hangul
*/
Expand Down Expand Up @@ -52,9 +56,9 @@ export class Hangul {
*/
insert(index: number, value: string | HangulBuilder): void {
if (value instanceof HangulBuilder) {
this.String = this.String.insert(index, value.build())
this.String = insert(this.String, index, value.build())
} else {
this.String = this.String.insert(index, value);
this.String = insert(this.String, index, value);
}
}

Expand Down Expand Up @@ -100,16 +104,16 @@ export class Hangul {
}
}

// Because of stability, decided to remove it.

/*
declare global {
interface String {
toHangul(): Hangul;
insert(ind: number, s: string): string;
}
}
String.prototype.toHangul = function (): Hangul {
return new Hangul(this.toString());
}
String.prototype.insert = function (ind: number, s: string): string {
return [this.slice(0, ind), s, this.slice(ind)].join('');
}
*/
2 changes: 1 addition & 1 deletion test/hangul.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Hangul
} from "../mod.ts"

const han = "테스트".toHangul();
const han = new Hangul("테스트");

console.log(han.toString());

Expand Down

0 comments on commit 2928f0e

Please sign in to comment.