jsコールバック関数の値と割り当て


1.簡単なコールバック
function demo(callback){
    callback(1)
}
demo(function(e) {
    console.log(e)  //1
})
2.戻り値
function demo(callback){
    var opts = {
        ids: [1,2,3,4],
        list: ['ho','yang','lee','chan']
    }
    callback(opts)
}
demo(function(e) {
    console.log(e) //{"ids":[1,2,3,4],"list":["ho","yang","lee","chan"]}
})
3.フィードバック値と割当値
function demo(originalOpts,callback){
    var opts = {
        ids: originalOpts.ids.concat([5,6,7]),
        list: originalOpts.list.concat(['xu','zhu','fu'])
    }
    callback(opts)
}
demo({
	ids: [1,2,3,4],
	list: ['ho','yang','lee','chan']
	},function(e) {
    console.log(e)  //{"ids":[1,2,3,4,5,6,7],"list":["ho","yang","lee","chan","xu","zhu","fu"]}
})