Vue
by antixrist
HTML
<div id="app">
<span v-text="notOptimized"></span>
<span v-text="optimized"></span>
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
Babel + JSX
new Vue({
el: "#app",
computed: {
staticData() {
console.log('call "staticData"');
return 42
},
notOptimized() {
console.time('notOptimized')
let result = 0;
for (let i = 0; i < 100000000; i++) {
result += this.staticData;
}
console.timeEnd('notOptimized')
return result;
},
optimized() {
console.time('optimized')
let result = 0;
const { staticData } = this
for (let i = 0; i < 100000000; i++) {
result += staticData;
}
console.timeEnd('optimized')
return result;
},
}
})