Skip to content

Instantly share code, notes, and snippets.

View aymanalzarrad's full-sized avatar
👨‍💻
9223372036854775807

Ayman Al Zarrad aymanalzarrad

👨‍💻
9223372036854775807
View GitHub Profile
@aymanalzarrad
aymanalzarrad / EloquentCheatSheet.md
Created March 10, 2022 17:21 — forked from avataru/EloquentCheatSheet.md
Eloquent relationships cheat sheet
@aymanalzarrad
aymanalzarrad / js-observables-binding.md
Created June 13, 2017 17:30 — forked from austinhyde/js-observables-binding.md
Vanilla JavaScript Data Binding

Observables

You don't really need a framework or fancy cutting-edge JavaScript features to do two-way data binding. Let's start basic - first and foremost, you need a way to tell when data changes. Traditionally, this is done via an Observer pattern, but a full-blown implementation of that is a little clunky for nice, lightweight JavaScript. So, if native getters/setters are out, the only mechanism we have are accessors:

var n = 5;
function getN() { return n; }
function setN(newN) { n = newN; }

console.log(getN()); // 5

setN(10);