Skip to content

Instantly share code, notes, and snippets.

@rndme
Last active April 12, 2024 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rndme/69ae954f39c84ed609b7f59f456d7aa9 to your computer and use it in GitHub Desktop.
Save rndme/69ae954f39c84ed609b7f59f456d7aa9 to your computer and use it in GitHub Desktop.
function Ohm(v, i, _){
(_=(k, get, set) => Object.defineProperty(this, k, {get, set, enumerable: 1}) && _)
("v", _=>v, x=>v=x)
("i", _=>i, x=>i=x)
("w", _=>v*i, x=>i=x/v)
("r", _=>v/i, x=>i=v/x);
}
var x = new Ohm(5, 2); // == {"v":5,"i":2,"w":10,"r":2.5}
x.r=10;
console.log(JSON.stringify(x)); // == {"v":5,"i":0.5,"w":2.5,"r":10}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment