我不习惯使用 this
并尝试让一些简单的函数来回传递它。我不太确定 javascript 期望什么,但我认为我做的不对。
$(".search-result").each(function() {
var x = $(this).find('.past-positions ol').children()
console.log(x)
//this prints as expected
pastJobs(this)
// this does not
})
function pastJobs() {
var x = $(this).find('.past-positions ol').children()
console.log(x)
// this prints as undefined
}
我认为可以将 this
传递给函数,但我认为我的做法不对。
我做错了什么?
最佳答案
改为尝试 pastJobs.call(this)
。
关于Javascript 将 this 传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325271/