Baseline Widely available
TypedArray.from()
ã¡ã½ããã¯ãé
å風ãªãã¸ã§ã¯ããå復å¯è½ãªãã¸ã§ã¯ãããæ°ããåä»ãé
åãçæãã¾ãããã®ã¡ã½ãã㯠Array.from()
ã¨ã»ã¼åãã§ãã
const uint16 = Int16Array.from("12345");
console.log(uint16);
// Expected output: Int16Array [1, 2, 3, 4, 5]
æ§æ
TypedArray.from(arrayLike, mapFn)
TypedArray.from(arrayLike, mapFn, thisArg)
ããã§ TypedArray
ã¯æ¬¡ã®ããããã§ãã
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
arrayLike
åä»ãé åã«å¤æããå復å¯è½ã¾ãã¯é å風ãªãã¸ã§ã¯ãã§ãã
mapFn
çç¥å¯
åä»ãé
åã®åè¦ç´ ã«å¯¾ãã¦å¼ã³åºã颿°ã§ããæå®ãããå ´åãé
åã«è¿½å ãããã¹ã¦ã®å¤ã¯æåã«ãã®é¢æ°ã«æ¸¡ããã代ããã« mapFn
ã®è¿å¤ãåä»ãé
åã«è¿½å ããã¾ãããã®é¢æ°ã¯ä»¥ä¸ã®å¼æ°ã§å¼ã³åºããã¾ãã
element
ç¾å¨å¦çããã¦ããåä»ãé åã®è¦ç´ ã§ãã
index
ç¾å¨å¦çããã¦ããåä»ãé åã®è¦ç´ ã®ã¤ã³ããã¯ã¹ã§ãã
thisArg
çç¥å¯
mapFn
ãå®è¡ããã¨ãã« this
ã¨ãã¦ä½¿ãå¤ã§ãã
æ°ãã TypedArray
ã¤ã³ã¹ã¿ã³ã¹ã§ãã
詳ãã㯠Array.from()
ãã覧ãã ããã
Array.from()
㨠TypedArray.from()
ã®éã«ã¯å¾®å¦ãªéããããã¾ãï¼ã¡ã¢: ä¸è¨ã§è¨åãã this
å¤ã¯ TypedArray.from()
ãå¼ã³åºããã this
å¤ã§ããã mapFn
ãå¼ã³åºãããã«ç¨ãã thisArg
弿°ã§ã¯ããã¾ããï¼ã
TypedArray.from()
ã«æ¸¡ããã this
ã®å¤ãã³ã³ã¹ãã©ã¯ã¿ã¼ã§ã¯ãªãã£ãå ´åã TypedArray.from()
ã§ TypeError
ãçºçãã¾ããããã«å¯¾ã㦠Array.from()
ãæ¢å®ã§æ°ãã Array
ãçæãã¾ããthis
ã§æ§ç¯ããããªãã¸ã§ã¯ã㯠TypedArray
ã¤ã³ã¹ã¿ã³ã¹ã§ãªããã°ãªãã¾ãããã Array.from()
㯠this
ã®å¤ãä»»æã®ãªãã¸ã§ã¯ãã«æ§ç¯ãããã¨ãã§ãã¾ããsource
ãã¤ãã¬ã¼ã¿ã¼ã®å ´åã TypedArray.from()
ã¯æåã«ã¤ãã¬ã¼ã¿ã¼ãããã¹ã¦ã®å¤ãåéããæ¬¡ã«ãã®ã«ã¦ã³ãã使ç¨ã㦠this
ã®ã¤ã³ã¹ã¿ã³ã¹ã使ããæå¾ã«ãã®ã¤ã³ã¹ã¿ã³ã¹ã«å¤ãè¨å®ãã¾ãã Array.from()
ã¯ã¤ãã¬ã¼ã¿ã¼ããå¤ãåãåãã¨ããããã®å¤ãè¨å®ããæå¾ã« length
ãè¨å®ãã¾ããTypedArray.from()
㯠[[Set]]
ã使ç¨ãã¾ãã Array.from()
㯠[[DefineOwnProperty]]
ã使ç¨ãã¾ãã å¾ã£ã¦ Proxy
ãªãã¸ã§ã¯ãã使ã£ã¦ããå ´åã¯ãæ°ããè¦ç´ ã追å ããã¨ãã« handler.set()
ã handler.defineProperty()
ã®ä»£ããã«å¼ã³åºããã¾ããArray.from()
ãã¤ãã¬ã¼ã¿ã¼ã§ã¯ãªãé
å風ãªãã¸ã§ã¯ããåãåã£ãã¨ãã¯ãç©´ããã®ã¾ã¾æ®ãã¾ãã TypedArray.from()
ã¯å¿
ãå¯é
å (dense array) ãçæãã¾ããconst s = new Set([1, 2, 3]);
Uint8Array.from(s);
// Uint8Array [ 1, 2, 3 ]
æååãã
Int16Array.from("123");
// Int16Array [ 1, 2, 3 ]
ã¢ãã¼é¢æ°ã¨ map ã®ä½¿ç¨
ã¢ãã¼é¢æ°ãããã颿°ã¨ãã¦ä½¿ç¨ãã¦è¦ç´ ãæä½ãã¾ãã
Float32Array.from([1, 2, 3], (x) => x + x);
// Float32Array [ 2, 4, 6 ]
æ°åãçæãã
Uint8Array.from({ length: 5 }, (v, k) => k);
// Uint8Array [ 0, 1, 2, 3, 4 ]
TypedArray 以å¤ã®ã³ã³ã¹ãã©ã¯ã¿ã¼ã«å¯¾ãã from() ã®å¼ã³åºã
from()
ã® this
å¤ã¯ TypedArray
ã¤ã³ã¹ã¿ã³ã¹ãè¿ãã³ã³ã¹ãã©ã¯ã¿ã¼ã§ãªããã°ãªãã¾ããã
function NotArray(len) {
console.log("NotArray called with length", len);
}
Int8Array.from.call({}, []); // TypeError: #<Object> is not a constructor
Int8Array.from.call(NotArray, []);
// NotArray called with length 0
// TypeError: Method %TypedArray%.from called on incompatible receiver #<NotArray>
function NotArray2(len) {
console.log("NotArray2 called with length", len);
return new Uint8Array(len);
}
console.log(Int8Array.from.call(NotArray2, [1, 2, 3]));
// NotArray2 called with length 3
// Uint8Array(3) [ 1, 2, 3 ]
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4