Skip to content

Instantly share code, notes, and snippets.

View wentout's full-sized avatar
😎
building teleport

wentout wentout

😎
building teleport
View GitHub Profile
@wentout
wentout / InstanceOfLies.js
Created March 12, 2024 11:34
improved Eric Elliott's instanceof lies example
function foo() { };
const bar = { a: 'a' };
Object
.setPrototypeOf(
foo.prototype,
bar
);
const baz = Object.create(foo.prototype);
console.log(baz instanceof foo);
@wentout
wentout / ArrayDotNotation_Habitable.js
Last active February 28, 2024 20:54
Array Dot Notation JS Example
'use strict';
const ogp = Object.getPrototypeOf;
const osp = Object.setPrototypeOf;
const MyArrayConstructor = function() {};
osp(MyArrayConstructor.prototype, new Array);
class MyArray extends MyArrayConstructor {
constructor(...args) {
super(...args);
@wentout
wentout / ClassInfinitLoop.js
Created February 8, 2024 11:00
Infinite Loops
class Base {
constructor() {
return new Extended;
}
}
class Extended extends Base {
constructor() {
super();
}
@wentout
wentout / ClassInstancePrototypeChainTest.js
Created January 12, 2023 16:48
Ptototype Inheritance just is not the same for Class instances not
class A {
a = 1
constructor() {
console.log('A constructor this.a : ', this.a);
this.a = 1;
console.log('A constructor this.a : ', this.a);
}
}
class B extends A {
@wentout
wentout / FunctionalInheritance.ts
Last active January 12, 2023 14:07
TypeScript Functional Inheritance with Prototypes working
const MyConstructor: IMyConstructor = function (this: MyConstructorInstance, name: string) {
this.name = name;
} as IMyConstructor;
MyConstructor.prototype.name = 'default';
MyConstructor.prototype._char = 'default';
Object.defineProperty(MyConstructor.prototype, 'char', {
get(this: MyConstructorInstance) {
return this._char;
},
@wentout
wentout / NamingConventionExample.js
Created August 5, 2022 09:11
Naming Convention Disambiguation on ChromeDevTools
const MethodName = 'MyMethodName';
var NamingObject = {
[MethodName]: function () {
this;
console.log(this.constructor.name); // MyMethodName
debugger;
}
};
@wentout
wentout / AssociatedMonoField.js
Last active July 23, 2022 06:02
monotonic types on field definitions and objects
let value = 123;
const MyGetSetTestClass = class {
get get() {
console.log('g0')
return function () {
console.log('g1')
return ++value;
}
@wentout
wentout / TheRing.js
Last active October 18, 2021 17:53
The Ring from Proxies
'use strict';
const a = { a: 1 };
const b = { b: 2 };
const c = { c: 3 };
const d = { d: 4 };
@wentout
wentout / DestructuringThisTest.js
Last active July 22, 2021 15:30
testing destructuring assignment `this` patterns
// By James M Snell @jasnell
// the first tweet:
// https://twitter.com/jasnell/status/1385464365046894599?s=20
class F {
a = 1;
b() {
return this.a;
}
@wentout
wentout / ProtoProxy.js
Last active February 13, 2021 11:00
demo for fields through prototype chain proxy declaration
'use strict';
const globalProto = Object.getPrototypeOf(Object.getPrototypeOf(Object));
const theirs = new Proxy(globalProto, {
get (target, prop, receiver) {
debugger;
console.log('p_get', prop);
},
set (target, prop, value, receiver) {