程式設計師是如何神不知鬼不覺的弄丟銀行1分錢的?
https://kknews.cc/zh-tw/finance/zpxln2q.html
[開發經驗分享][JavaScript]浮點數運算出現一堆小數位數
https://dotblogs.com.tw/WillianHsiaoDotNetBLog/2020/01/15/JavascriptFloatCaculateBug?fbclid=IwAR0SnYG7FnesbfENWCsOT_ceGxqab6Q1dksJ3qIr-pe65m55wNBlWLc0Ns0
精確的浮點數運算 ?
https://medium.com/pyladies-taiwan/%E7%B2%BE%E7%A2%BA%E7%9A%84%E6%B5%AE%E9%BB%9E%E6%95%B8%E9%81%8B%E7%AE%97-28d34e652e51
javascript How does the double exclamation (!!) work in javascript?
| value | !value | !!value |
| false | true | false |
| true | false | true |
| null | true | false |
| undefined | true | false |
| 0 | true | false |
| -0 | true | false |
| 1 | false | true |
| -5 | false | true |
| NaN | true | false |
| '' | true | false |
| 'hello' | true | false |
javascript functions parm default value
https://stackoverflow.com/questions/6600868/set-default-value-of-javascript-object-attributes
// default num: 0, unit: 'pics'
function items(op) {
const { num, unit } = Object.assign({}, { num: 0, unit: 'pics'}, op);
}
javascript firestore object sort
const bookListsQuery = await modules.firestore.collection('books')
.get();
const sortedObj = Object.values(bookListsQuery.docs).sort(function(a, b){
console.log('a %s b %s', a.data().order, b.data().order)
return Number(a.data().order) > Number(b.data().order);
});
sortedObj.forEach(function(doc){
console.log(doc.data())
});
other way
object use map to array, then it sorted.
const bookListsQuery = await modules.firestore.collection('books')
.get();
const sortedArr = bookListsQuery.docs.map(function (doc) { // 轉換成array
return doc.data()
});
sortedArr.sort(function compare(a, b) {
return a.order > b.order; // 升 小->大
});
sortedArr.forEach(function(data){
console.log(data.data())
})
==========
Sorting multiple object properties with JavaScript
https://bithacker.dev/javascript-object-multi-property-sort
let students = [{
firstName: 'John',
lastName: 'Appletree',
grade: 12
},{
firstName: 'Mighty',
lastName: 'Peachtree',
grade: 10
},{
firstName: 'Kim',
lastName: 'Appletree',
grade: 11
},{
firstName: 'Shooter',
lastName: 'Appletree',
grade: 12
}];
let sortBy = [{
prop:'grade',
direction: -1
},{
prop:'lastName',
direction: 1
}];
array.sort(function(a,b){
let i = 0, result = 0;
while(i < sortBy.length && result === 0) {
result = sortBy[i].direction*(a[ sortBy[i].prop ].toString() < b[ sortBy[i].prop ].toString() ? -1 : (a[ sortBy[i].prop ].toString() > b[ sortBy[i].prop ].toString() ? 1 : 0));
i++;
}
return result;
})
javascript console.log object
console.log('show value string, object %s %O', var.string, var.object);
async await Promise.all
async getaaa()
async getbbb()
async getccc()
=======new way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
}))
await Promise.all( xxxxxx.map(async (value, index) =>{
bbb = await getbbb()
}))
=======old way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
bbb = await getbbb()
ccc = await getccc()
}))
}
1. map usually return something, here just throw
2. if use foreach(), get error. Like foreach is not function, can't async await.
old way aaa order is good, but bbb ccc order is bad.
new way all aaa bbb ccc order is ok.
async getbbb()
async getccc()
=======new way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
}))
await Promise.all( xxxxxx.map(async (value, index) =>{
bbb = await getbbb()
}))
await Promise.all( xxxxxx.map(async (value, index) =>{
ccc = await getccc()
}))
}
=======old way=======
async refreshall(){
await Promise.all( xxxxxx.map(async (value, index) =>{
aaa = await getaaa()
bbb = await getbbb()
ccc = await getccc()
}))
}
1. map usually return something, here just throw
2. if use foreach(), get error. Like foreach is not function, can't async await.
old way aaa order is good, but bbb ccc order is bad.
new way all aaa bbb ccc order is ok.
call by value call by reference object array push
Problem:
array A
A.push(item)
item is object from for or map or foreach....etc
show A all add item is same.......
Solve:
var txxxxx = [] // xxxx is any word
=====loop start=====
txxxx[index] = item //index is from for or map or foreach...etc
ot = {
xxxx: txxxx[index]
}
A.push(ot)
=====loop end=====
array A
A.push(item)
item is object from for or map or foreach....etc
show A all add item is same.......
Solve:
var txxxxx = [] // xxxx is any word
=====loop start=====
txxxx[index] = item //index is from for or map or foreach...etc
ot = {
xxxx: txxxx[index]
}
A.push(ot)
=====loop end=====
Preloading images and executing code only after all images have loaded
http://www.javascriptkit.com/javatutors/preloadimagesplus.shtml
http://fragged.org/preloading-images-using-javascript-the-right-way-and-without-frameworks_744.html
http://fragged.org/preloading-images-using-javascript-the-right-way-and-without-frameworks_744.html
[轉]jQuery 之 checkbox 及 radio 設定值的
http://note.tc.edu.tw/175.html
[radio 取值]
以下範例示範當使用者按下 submit ( id=sb1 ) 時的檢查動作,其中 radio 的 name=doway
$("#sb1").click(function(){
var method =$("input[name='doway']:checked").val(); //radio 取值,注意寫法
if( typeof(method) == "undefined"){ // 注意檢查完全沒有選取的寫法,這行是精華
alert( "請選取操作方式!");
return false;
}
[radio 取值]
以下範例示範當使用者按下 submit ( id=sb1 ) 時的檢查動作,其中 radio 的 name=doway
$("#sb1").click(function(){
var method =$("input[name='doway']:checked").val(); //radio 取值,注意寫法
if( typeof(method) == "undefined"){ // 注意檢查完全沒有選取的寫法,這行是精華
alert( "請選取操作方式!");
return false;
}
[轉]不會不專業!只要懂這五題你就是 Pro 級的 JavaScript 工程師
http://buzzorange.com/techorange/2015/08/18/humans-create-softwarehow-do-you-judge-a-javascript-programmer-by-only-5-questions/
Q1:你能解釋出什麼是 apply 函數嗎?
當之後你在建立 Library 時你一定要記得最常使用的 apply 函數
Q2:你能跟我解釋一下什麼是 map 嗎?不仿就再問問有關 reduce 方法。如果你不懂什麼是 map ,這代表著你在功能性撰寫程式程度是零!但千萬別放棄治療,建議你從這快開始你的學習之旅:A dirt simple introduction to higher order functions in JavaScript.
Q3:能解釋什麼是 bind 嗎?
Q4:解釋一下什麼是 closures ?
Q1:你能解釋出什麼是 apply 函數嗎?
當之後你在建立 Library 時你一定要記得最常使用的 apply 函數
Q2:你能跟我解釋一下什麼是 map 嗎?不仿就再問問有關 reduce 方法。如果你不懂什麼是 map ,這代表著你在功能性撰寫程式程度是零!但千萬別放棄治療,建議你從這快開始你的學習之旅:A dirt simple introduction to higher order functions in JavaScript.
Q3:能解釋什麼是 bind 嗎?
Q4:解釋一下什麼是 closures ?
訂閱:
文章 (Atom)