From 5a1f3c45a1b183602c6e5145f14d749d8d073d10 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 15 Mar 2022 20:01:12 +0800 Subject: [PATCH] update --- js/lib/core.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/js/lib/core.js b/js/lib/core.js index 6db98a2..b22013c 100644 --- a/js/lib/core.js +++ b/js/lib/core.js @@ -1,3 +1,25 @@ +if (!String.prototype.size) { + Object.defineProperty(String.prototype, 'size', { + get() { + var n = 0 + for (let it of this) { + n++ + } + return n + } + }) + + Object.defineProperty(String.prototype, 'at16', { + value(n) { + var tmp = [] + for (let it of this) { + tmp.push(it) + } + return tmp[n] + } + }) +} + export class Enum { #dict_k = Object.create(null) #dict_v = Object.create(null)