Skip to content

Instantly share code, notes, and snippets.

@arccoza
arccoza / index.js
Last active August 11, 2023 07:35
JavaScript Callable Object using closures & prototypes
'use strict'
class Callable extends Function {
constructor() {
var closure = function(...args) { return closure._call(...args) }
// Or without the spread/rest operator:
// var closure = function() {
// return closure._call.apply(closure, arguments)
// }
return Object.setPrototypeOf(closure, new.target.prototype)
@arccoza
arccoza / index.js
Last active March 20, 2024 15:12
JavaScript Callable Object using proxy
'use strict'
class Callable extends Function {
constructor() {
super()
return new Proxy(this, {
apply: (target, thisArg, args) => target._call(...args)
})
}
@arccoza
arccoza / index.js
Last active November 28, 2019 06:23
JavaScript Callable Object using bind
'use strict'
class Callable extends Function {
constructor() {
super('...args', 'return this._bound._call(...args)')
// Or without the spread/rest operator:
// super('return this._bound._call.apply(this._bound, arguments)')
this._bound = this.bind(this)
return this._bound
@arccoza
arccoza / index.js
Last active August 11, 2023 07:36
JavaScript Callable Object using callee
'use strict'
class Callable extends Function {
constructor() {
super('return arguments.callee._call.apply(arguments.callee, arguments)')
// We can't use the rest operator because of the strict mode rules.
// But we can use the spread operator instead of apply:
// super('return arguments.callee._call(...arguments)')
}
@arccoza
arccoza / index.html
Last active December 8, 2017 08:40
Fastest way to fill a string #jsbench #jsperf (http://jsbench.github.io/#3505f93def05b634ff054fc6a0d7080d) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Fastest way to fill a string #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@arccoza
arccoza / index.html
Last active December 8, 2017 07:39
Fastest way to fill an array #jsbench #jsperf (http://jsbench.github.io/#188cbe041026832a50a61a0fd674e1be) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Fastest way to fill an array #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@arccoza
arccoza / index.html
Created December 4, 2017 05:50
String / RegExp operations (http://jsbench.github.io/#9f7f6df6b0e90fc2e1a3b94384e5b2dc) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>String / RegExp operations</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@arccoza
arccoza / index.html
Created December 4, 2017 04:34
Fastest way to split a string (http://jsbench.github.io/#564b3aa597288c2a333619f2aa2297f7) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Fastest way to split a string</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@arccoza
arccoza / index.html
Created December 4, 2017 03:51
Fastest way to slice an array (http://jsbench.github.io/#c21f6f4d50a24a4f39fa2bd8455e6bb1) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Fastest way to slice an array</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@arccoza
arccoza / javascript: convert string to array of chars performance.js
Created May 30, 2017 03:32
javascript: convert string to array of chars performance created by arccoza - https://repl.it/IWyr/6
var str = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
進善公愛載懸千間前死断直周税。稿実写使松出子府上難向飾幹超。属三闘与結社京政郎回終線見権競式部文賀帰。星画直小和氏路芸間提別対人面。年蹊雪北聞詐節禁画藤社念歳歴歳子読及。績転席上席作市放将図教海的横表載脚大。話能求全耳北時議定著測質稲護紀。農済哉無総図出悲質情容経。以野態自亡必員災博新非脳察趣着車。`
var arr = null
var tests = {
'Object.assign'(its) {
for(let i = 0; i < its; i++)
arr = Object.assign([], str)
},