Array push

var app=function () {

};
var obj= {

_get_:[],
_post_:[]

}
app.get=function (str,callback) {

obj._get_.push({str:callback});
console.log(JSON.stringify(obj));//{"_get_":[{}],"_post_":[]} push

};

app.get ("/ login",function () {

)
console.log("hello");

});

May.22,2021

obj._get_.push({[str]:callback});

question 1:
push you should refer to the way upstairs:

obj._get_.push({[str]:callback});

or for compatibility reasons, use the following method:

let tmp = {}
tmp[str] = callback
obj._get_.push(tmp)

question 2:
JSON.stringify when serializing a function, if the function appears in the object, directly ignores . If it is in an array, it will be converted to null :

.
let a = {hello: function() {console.log('hello')}}
JSON.stringify(a) // "{}"
a = [function() {console.log('hello')}]
JSON.stringify(a) // "[null]"

clipboard.png

so, it's not that there is no push in it. It's just that you didn't drop the function Filter when you JSON.stringify . You can see the elements inside if you print obj directly.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7c37c7-1752d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7c37c7-1752d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?