This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uses arrow functions to define methods seperatly from data, like an alternative to .prototype. | |
var x=function(){ | |
return { // public methods: | |
get: ( )=> this.val, | |
set: (v)=> this.val=v, | |
}; | |
}.call({ // private state: | |
val: 902 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// uses arrow functions to define methods and creates an un-breakable bind to `this` | |
var x=new function(){ | |
Object.assign(this, { | |
val : 530, | |
get: ( )=> this.val, | |
set: (v)=> this.val=v, | |
}); | |
}; | |
x.get(); // 530 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<vcc-demo></vcc-demo> | |
<script src="http://danml.com/bundle/rndme.cia_rndme.vcc_.js"></script> | |
<script> | |
var store = CIA({ | |
INC: function(state, n) { | |
state.index+= (n||1); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(window, "__", {set: Object.freeze}); | |
// ex usage: | |
var state= __={ | |
a: 1, | |
b: 3, | |
c: __=[1,2,3, __={ z: 7 } ] | |
}; | |
// try to mutate: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function survey(object) { | |
function scan(ob, p, x) { | |
var k, v; | |
for(k in ob) { | |
if(!ob.hasOwnProperty(k)) continue; | |
v=ob[k]; | |
if(typeof v === "object" && v && !+v) { | |
scan(v, p + "." + k, x); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cache(size, duration) { | |
// an object cache, where you can set max size or time or both, and it maintains shit for you, and quickly too | |
var index = {}, stack = [], | |
count = 0; | |
size = size || 100; | |
duration = duration || 1000 * 60 * 5; | |
function add(key, val) { | |
count++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var screenShotDialog = document.createElement("DIALOG"); | |
document.body.appendChild(screenShotDialog).innerHTML="Hello World"; | |
screenShotDialog.showModal(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var counter=1; | |
addEventListener("plus", function(e){ | |
console.log(counter++); | |
}); | |
dispatchEvent(new Event("plus")); | |
dispatchEvent(new Event("plus")); | |
dispatchEvent(new Event("plus")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ViewModel(rootElement){ | |
rootElement = rootElement || document; | |
var model = Object.create(null); | |
function updateElement(elm){ | |
var key = elm.getAttribute("bind"), | |
pre = elm.getAttribute("pre") || "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isSorted(arr, fn){ | |
return !arr.some(function(a,b,c){ | |
if(!b) return; | |
return fn(a, c[b-1])!==1; | |
}); | |
} |