You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
I probably have some errors in here, but I believe this matches the spec text.
Array.prototype.at=functionat(k){// 1. Let O be ? ToObject(this value)if(this==null){thrownewTypeError("Array.prototype.at called on null or undefined");}constO=Object(this);// 2. Let len be ? LengthOfArrayLike(O).constlen=Math.min(Math.max(Math.trunc(O.length)||0,0),2097151);k=Math.trunc(k)||0;if(k<0)k+=len;if(0<=k&&k<len)returnO[k];}Array.prototype[Symbol.unscopables].at=true;String.prototype.at=functionat(k){// 1. Let O be ? RequireObjectCoercible(this value).if(this==null){thrownewTypeError("String.prototype.at called on null or undefined");}// 2. Let S be ? ToString(O).constS=String.prototype.concat.call(this);k=Math.trunc(k)||0;if(k<0)k+=S.length;returnS[k];}(function(TypedArray){TypedArray.prototype.at=functionat(k){constlen=Reflect.get(TypedArray.prototype,"length",this);k=Math.trunc(k)||0;if(k<0)k+=len;returnthis[k];}})(Object.getPrototypeOf(Int8Array));
The text was updated successfully, but these errors were encountered:
if (k < 0) k += S.length; should be if (k < 0) k += len; in the TypedArray polyfill.
Also, wouldn’t it be better to check the property’s existence first?
if(!Array.prototype.hasOwnProperty("at")){Object.defineProperty(Array.prototype,"at",{writable: true,configurable: true,value: {at(n){// Polyfill for Array.prototype.at here.}}.at});}
(The method syntax and property descriptors are just there to make the method definition as close as possible to existing methods, e.g. new Array.prototype.at(); shouldn’t work, so function shouldn’t be used, etc.)
(As opposed to "rough" polyfill.)
I probably have some errors in here, but I believe this matches the spec text.
The text was updated successfully, but these errors were encountered: