CARVIEW |
Select Language
HTTP/2 302
date: Fri, 25 Jul 2025 19:22:36 GMT
content-type: text/html; charset=utf-8
content-length: 0
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
location: https://gist.github.com/Jxck/1073547
cache-control: no-cache
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
set-cookie: _gh_sess=OeSYb0DEQTQae4dHFRNlscbh9pWxiafkcszri%2FCyFETpKMJ4InbLdQ0YulbYeYhAWxvCtniMXA9zpdlYTkvEEBqgZWWTRBL8s7Plxj%2FKWm5q7UzBlrDdlc2vEDAzxH51PsXjdh1rIlk%2BQW%2Bo62k9Awq1XgYCWEu%2FXf74aZeiDA8uxjDOkDgg%2BdHfZWiPbU%2B6pH6p88KSl%2BLUGmTDZ%2BmHsyRxoQiLxUOYL8LGJ7FJ0vwO49EDT1aGWeYYMfpkVbIt4MauN8GD98WIeCsPKWLZBw%3D%3D--ZRueh1oJqHOuQXdT--fUui%2BL2sFXz3pX1NKZNfmQ%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1101562143.1753471355; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 19:22:35 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Sat, 25 Jul 2026 19:22:35 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: E818:123CFB:472AC:5D591:6883D97B
HTTP/2 200
date: Fri, 25 Jul 2025 19:22:37 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
etag: W/"a106927d2f167cc9dd645b259b7c6d33"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
x-github-request-id: E818:123CFB:472E3:5D608:6883D97B
The sample usage of ECMA 5 Features Implemented in V8 · GitHub
Show Gist options
Save Jxck/1073547 to your computer and use it in GitHub Desktop.
{{ message }}
Instantly share code, notes, and snippets.
Created
July 9, 2011 12:02
-
Star
22
(22)
You must be signed in to star a gist -
Fork
10
(10)
You must be signed in to fork a gist
-
Save Jxck/1073547 to your computer and use it in GitHub Desktop.
The sample usage of ECMA 5 Features Implemented in V8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* The sample usage of ECMA 5 Mozilla Features Implemented in V8 | |
* https://github.com/joyent/node/wiki/ECMA-5-Mozilla-Features-Implemented-in-V8 | |
* You can use thease new feature of ECMA5 on Node.js as you like. | |
* because there is no IE :) | |
* Order is deferent form original wiki. | |
* Sources are Checked on Node.js v0.5.0(unstable), v0.4.9(stable) | |
* | |
* you can execute this file. | |
* $ node ecma5_on_v8.js | |
* | |
* @author Jxck | |
* @license https://www.opensource.org/licenses/mit-license.php (The MIT License). | |
*/ | |
// console.log is tooooooo long :( | |
var log = console.log; | |
log('---- Object -----'); | |
var obj = { | |
_str: 'default', | |
get str() { // getter | |
return this._str + '!'; | |
}, | |
set str(val) { // setter | |
this._str = val.trim(); | |
} | |
}; | |
log(obj.str); // "default!" | |
obj.str = ' asdf '; | |
log(obj.str); // "asdf!" | |
log('---- Object.defineProperty(obj, prop, desc) ----'); | |
var obj = {}; | |
Object.defineProperty(obj, 'num', { | |
value: 10, | |
writable: false, | |
enumerable: false, | |
configurable: false | |
}); | |
log(obj.num); // 10 | |
for (var i in obj) { | |
log(i); // not display | |
} | |
obj.num = 20; | |
log(obj.num); // still 10 | |
log('---- Object.defineProperties(obj, props) ----'); | |
var obj = {}; | |
Object.defineProperties(obj, { | |
num: { | |
value: 4, | |
writable: false, | |
enumerable: false, | |
configurable: false | |
}, | |
root: { | |
get: function() { | |
return Math.pow(this.num, 0.5); | |
} | |
} | |
}); | |
log(obj.num); // 4 | |
log(obj.root); // 2 | |
log('---- Object.create(proto, props) ----'); | |
// extends x, y | |
var obj = Object.create({x: 10, y: 20}); | |
log(obj.x); // 10 | |
log(obj.y); // 20 | |
var obj = Object.create(null); | |
log(obj); // not extend anything | |
var obj = Object.create(Object.prototype); | |
log(obj); // same as {} , new Object() | |
var obj = Object.create({x: 10, y: 20}, { | |
z: { | |
value: 30, | |
writable: true | |
}, | |
sum: { | |
get: function() { | |
return this.x + this.y + this.z; | |
} | |
} | |
}); | |
log(obj.x); // 10 | |
log(obj.y); // 20 | |
log(obj.z); // 30 | |
log(obj.sum); // 60 | |
log('---- Object.keys(obj) ----'); | |
function o() { | |
this.a = 1; | |
} | |
log(Object.keys(new o())); // [ 'a' ] | |
function p() { | |
this.b = 2; | |
} | |
p.prototype = new o(); | |
log(Object.keys(new p())); // [ 'b' ] | |
var obj = Object.create({a: 10, b: 20}, { | |
x: { | |
value: 30, | |
enumerable: true | |
}, | |
y: { | |
value: 40, | |
enumerable: false | |
} | |
}); | |
log(Object.keys(obj)); // [ 'x' ] | |
log('---- Object.getOwnPropertyNames(obj) ----'); | |
var obj = Object.create({a: 10, b: 20}, { | |
x: { | |
value: 30, | |
enumerable: true | |
}, | |
y: { | |
value: 40, | |
enumerable: false | |
} | |
}); | |
log(Object.getOwnPropertyNames(obj)); // [ 'y', 'x' ] | |
log('---- Object.getPrototypeOf(obj) ----'); | |
var obj = Object.create({a: 10, b: 20}, { | |
x: { | |
value: 30, | |
enumerable: true | |
}, | |
y: { | |
value: 40, | |
enumerable: false | |
} | |
}); | |
log(Object.getPrototypeOf(obj)); // { a: 10, b: 20 } | |
log('---- Object.getOwnPropertyDescriptor(obj, property) ----'); | |
var obj = Object.create({a: 10, b: 20}, { | |
x: { | |
value: 30, | |
enumerable: true | |
}, | |
y: { | |
value: 40, | |
enumerable: false | |
} | |
}); | |
log(Object.getOwnPropertyDescriptor(obj, 'x')); | |
// { value: 30, | |
// writable: false, | |
// enumerable: true, | |
// configurable: false } | |
log('---- Object.preventExtensions(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
Object.preventExtensions(obj); | |
// obj.x = 30; // TypeError: Can't add property x, object is not extensible | |
log('---- Object.isExtensible(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
log(Object.isExtensible(obj)); // true | |
Object.preventExtensions(obj); | |
log(Object.isExtensible(obj)); // false | |
log('---- Object.seal(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
Object.seal(obj); | |
obj.a = 30; | |
log(obj.a); // 30 | |
// obj.x = 30; // TypeError: Can't add property x, object is not extensible | |
log('---- Object.isSealed(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
Object.seal(obj); | |
log(Object.isSealed(obj)); // true | |
log('---- Object.freeze(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
Object.freeze(obj); | |
obj.a = 30; | |
log(obj.a); // 10 | |
log('---- Object.isFrozen(obj) ----'); | |
var obj = {a: 10, b: 20}; | |
Object.freeze(obj); | |
log(Object.isFrozen(obj)); // true | |
log('---- isPrototypeOf(obj) ----'); | |
var proto = {a: 10, b: 20}; | |
var obj = Object.create(proto); | |
log(proto.isPrototypeOf(obj)); // true | |
log('---- bind(thisArg[, arg1[, argN]]) ----'); | |
var f = function() { | |
return this.a + this.b; | |
}; | |
log(f()); // NaN | |
var g = f.bind({ a: 10, b: 20 }); | |
log(g()); // 30 | |
var f = function(c) { | |
return this.a + this.b + c; | |
}; | |
log(f()); // NaN | |
var g = f.bind({ a: 10, b: 20 }, 30); | |
log(g()); // 60 | |
var f = function(c, d) { | |
return this.a + this.b + c + d; | |
}; | |
log(f()); // NaN | |
var g = f.bind({ a: 10, b: 20 }, 30); | |
log(g(40)); // 100 | |
log('---- JSON.stringify(obj [, replacer [, space]]) ----'); | |
log(JSON.stringify({ a: 1 })); | |
log(JSON.stringify([1, 2, 3], function replacer(key, value) { | |
if (!Array.isArray(value)) { | |
return value; | |
} | |
var len = value.length; | |
var result = { length: len }; | |
for (var i = 0; i < len; ++i) { | |
result[i] = value[i]; | |
} | |
return result; | |
})); | |
log(JSON.stringify({ a: 1, b: 2}, null, 2)); | |
log(JSON.stringify({ a: 1, b: 2}, null, 4)); | |
log(JSON.stringify({ a: 1, b: 2}, null, '\t')); | |
log('---- JSON.parse(string) ----'); | |
var s = JSON.stringify({ a: 1, b: 0 }); | |
log(JSON.parse(s)); | |
log( | |
JSON.parse(s, function(key, value) { | |
if (value === 0) | |
value = false; | |
else if (value === 1) { | |
value = true; | |
} | |
return value; | |
}) | |
); | |
log('---- trim(), trimRight(), trimLeft() ----'); | |
log(' abc '.trim()); | |
log(' abc '.trimRight()); | |
log(' abc '.trimLeft()); | |
log('---- Array.isArray(array) ----'); | |
log(Array.isArray([])); | |
log('---- indexOf(value) ----'); | |
log(([1, 2, 2, 3]).indexOf(2)); | |
log('---- lastIndexOf(value) ----'); | |
log(([1, 2, 2, 3]).lastIndexOf(2)); | |
log('---- filter(callback) ----'); | |
log( | |
([1, 2, 3, 4]).filter(function(x) { | |
return x > 2; | |
}) | |
); | |
log('---- forEach(callback) ----'); | |
([1, 2, 3]).forEach(function(x) { | |
log(x * 2); | |
}); | |
log('---- every(callback) ----'); | |
log( | |
([1, 2, 3]).every(function(x) { | |
return x > 0; | |
}) | |
); | |
log( | |
([1, 2, 3]).every(function(x) { | |
return x > 1; | |
}) | |
); | |
log('---- some(callback) ----'); | |
log( | |
([1, 2, 3]).some(function(x) { | |
return x > 2; | |
}) | |
); | |
log( | |
([1, 2, 3]).some(function(x) { | |
return x > 3; | |
}) | |
); | |
log('---- map(callback) ----'); | |
log( | |
([1, 2, 3]).map(function(x) { | |
return x * 2; | |
}) | |
); | |
log('---- reduce(callback[, initialValue]) ----'); | |
log( | |
(['a', 'b', 'c']).reduce(function(x, y) { | |
return x + y; | |
}) | |
); | |
log( | |
(['a', 'b', 'c']).reduce(function(x, y) { | |
return x + y; | |
}, '*') | |
); | |
log('---- reduceRight(callback[, initialValue]) ----'); | |
log( | |
(['a', 'b', 'c']).reduceRight(function(x, y) { | |
return x + y; | |
}) | |
); | |
log( | |
(['a', 'b', 'c']).reduceRight(function(x, y) { | |
return x + y; | |
}, '*') | |
); | |
log('---- Date.now() ----'); | |
log(Date.now()); | |
log('---- toISOString() ----'); | |
log((new Date()).toISOString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can’t perform that action at this time.