Skip to content

Instantly share code, notes, and snippets.

@batazo
batazo / .gitlab-ci.yml
Created January 24, 2024 00:33 — forked from transitive-bullshit/.gitlab-ci.yml
GitLab CI Detox React Native Example
stages:
- E2E
.ios_base:
tags:
- macOS
- swiftlint
cache:
paths:
- node_modules
@batazo
batazo / PrivateInstanceMethods.js
Created July 3, 2022 19:10
Private instance methods and accessors
class Banner extends HTMLElement {
// Private variable that cannot be reached directly from outside, but can be modified by the methods inside:
#slogan = "Hello there!"
#counter = 0
// private getters and setters (accessors):
get #slogan() {return #slogan.toUpperCase()}
set #slogan(text) {this.#slogan = text.trim()}
@batazo
batazo / Class-static.js
Created July 3, 2022 19:07
STATIC FIELDS
class Translator {
static translations = {
yes: 'ja',
no: 'nein',
maybe: 'vielleicht',
};
static englishWords = [];
static germanWords = [];
static { // (A)
for (const [english, german] of Object.entries(this.translations)) {
@batazo
batazo / Temoral-Function.js
Created July 3, 2022 19:00
Temporal Functions
const date = Temporal.Now.plainDateISO(); // Gets the current date
date.toString(); // returns the date in ISO 8601 date format
// If you additionally want the time:
Temporal.Now.plainDateTimeISO().toString(); // date and time in ISO 8601 format
@batazo
batazo / Class static initialization blocks.js
Created July 3, 2022 18:54
Class static initialization blocks
class User {
isActive = false;
get getStatus(){
if(!this.#isActive){
throw new Error('User is not active');
}
return this.#isActive;
}
}
@batazo
batazo / error.cause.js
Created July 3, 2022 18:48
error.cause
try {
const result = 2 / 0;
console.log(result);
} catch (error) {
console.err(error);
throw new Error('Something went wrong', { cause: error });
}
@batazo
batazo / RegExp match indices.js
Created July 3, 2022 18:45
RegExp match indices
const fruits ="Fruits:apples, oranges, pears";
const regex = /(apples)/gd;
const matches = [...fruits.matchAll(regex)];
console.log(matches[0]);
@batazo
batazo / Object.hasOwn.js
Created July 3, 2022 18:34
Object.hasOwn()
const person = Object.create(null);
person.age = 21;
if (Object.hasOwn(person, 'age')) {
console.log(person.age); // true - works regardless of how the object was created
}
if (person.hasOwnProperty('age')){ // throws error - person.hasOwnProperty is not a function
console.log('hasOwnProperty: ', person.age);
}
@batazo
batazo / AT-Method-example.js
Created July 3, 2022 18:27
AT METHOD FOR INDEX
const fruits = ['apples', 'oranges', 'pears'];
console.log(fruits[fruits.length - 1]); // pears
console.log(fruits.at(0)); // apples
console.log(fruits.at(-1)); // pears