Function.prototype.myApply = function(context) {
if (typeof context === 'undefined' || context === null) {
context = window
}
context.fn = this
let args = arguments[1]
let result
if (args) {
result = context.fn(...args)
} else {
result = context.fn()
}
delete context.fn
return result
}
delete context.fn这一步的意义是什么,有什么好处吗?
相关问题
- Select first row from multiple dataframe and bind
- Improve this code by eliminating nested for cycles
- Pandas resample FutureWarning
- Scala apply method call as parentheses conflicts w
- Apply function to each cell of matrix in R
相关文章
- 为什么要delete context.fn
- Apply a function to a specified range; Rate of Cha
- R: Webscraping a list of URLs to get a DataFrame
- Set column names while calling a function
- Pandas groupby/apply has different behaviour with
- Help me replace a for loop with an “apply” functio
- R plyr, data.table, apply certain columns of data.
- How to apply rolling functions in a group by objec
按我的理解应该是把分配的内存给释放掉
如果没有那一步的话
那么当你调用 myApply() 之后
fn 这个方法就会留在调用的对象上
这显然是不对的