2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(小ネタ)javascriptでの、オブジェクトのメンバ呼び出しで数バイト削る努力をしてみる

Posted at

小ネタです

仕様の話

 javascriptはメンバ関数の呼び出しに.の代わりに、["メンバ名"]でも呼び出せる。
 オブジェクトのプロパティに関数オブジェクトが入ってるだけなので、そりゃそうかって話。

仕様の話2

 メンバの参照は、変数でも行える。

var hoge="document";
window[hoge] ; //window.document

仕様の話3

 変数名は、数字で始まらなければ、英数字と特定の記号、もしくはunicode文字列が使える

UTF-8の話

 日本語は3バイト使うけど、アラビア語、ヘブライ語はUTF-8で2バイト。

要するに

 文字数×出現個数が、文字数+7文字以上のものを書き換えると元が取れる計算。
 さらに、左右反転するので、ぱっと見動くように見えないコードができる。

var ج=JSON,ح="stringify",خ="parse";
console.dir(ج[خ](ج[ح]({hello:"world"})));
//==>Object {hello: "world"}
//元:console.dir(JSON.parse(JSON.stringify({hello:"world"})));

もしかするとファイルサイズ減るかも?

 適当にパーサ書いて置換したりしてみましたが、そんなに減りませんでした。
 いつかどこかでまじめに検証する予定。

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?