Table of Content
- Javascript
- Vuejs - {:.} Style scoped - {:.} V-btn div pattern - {:.} @Click
- Javascript - {:.} Array to Mp
- Important for ES6
Javascript
- Array.prototype.map vs Array.prototype.forEach
- excute speed ref : https://codeburst.io/javascript-map-vs-foreach-f38111822c0f
- mdn : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
// forEach
arr.forEach((num, index) => {
return (arr[index] = num * 2);
});
// map
var array1 = [1, 4, 9, 16];
// pass a function to map
const map1 = array1.map(x => x * 2);
console.log(map1);
// expected output: Array [2, 8, 18, 32]
Vuejs
Style scoped
- style scoped는 자식 컴포넌트 까지 전달 되지 않는다.
V-btn div pattern
<v-layout>
<div>
<v-btn><v-icon>delete</v-icon></v-btn>
</div>
</v-layout>
<style>
button {
margin: 0;
}
</style>
@Click
<v-btn @click="testA()" icon flat><v-icon>delete</v-icon></v-btn>
<v-btn @click="testB" icon flat><v-icon>delete</v-icon></v-btn>
<v-btn @click="testC(index, $event)" icon flat><v-icon>delete</v-icon></v-btn>
<script>
{
methods: {
testA: function(a) {
console.log(a) // expected output is undefined
},
testB: function(a) {
console.log(a); // expected output is event
},
testC: function(index, event){
}
}
}
</script>
Javascript
Array to Mp
var arr = [
{ key: "foo", val: "bar" },
{ key: "hello", val: "world" }
];
var result = arr.reduce(function(map, obj) {
map[obj.key] = obj.val;
return map;
}, {});
console.log(result);
Important for ES6
// if find object
const index = myArray.indexOf(targetObject); // don't
const indexOfStevie = myArray.findIndex(i => i.hello === "stevie"); // do
Today I Learned