Anti-global namespace stuff
Just fiddling a bit with everything under a MYAPP object.
by mich
HTML
<button onclick="MYAPP.interface.omgAction1()">Action 1</button>
<br />
<div id="console">
</div>
CSS
body { margin:1px; padding:1px; }
#console {
width: 100%;
height: 100%;
position: fixed;
overflow: auto;
background: #000;
color: #0F0;
font-family: monospace;
font-size: 12px;
padding: 5px;
border: solid 1px #0F0;
}
button {
border: solid 1px #090;
background: #020;
color: #0F0;
}
JavaScript
var MYAPP = {
value: 0,
increment: function(inc) {
this.value += typeof inc === 'number' ? inc : 1;
},
getValue: function() {
return this.value;
},
console: {
log: function(logContent) {
document.getElementById('console').innerHTML += "<br />" + logContent;
}
},
interface: {
omgAction1: function( ) {
MYAPP.increment(2);
MYAPP.console.log(MYAPP.getValue());
}
}
}