您最喜欢的Mootools/Prototype原生对象原型是什么? [英] What are your favorite Mootools/Prototype native object prototypes?
问题描述
我们的Mootoolers和Prototypers(在此站点上很少见)通常带有一个便捷的工具箱,这些工具箱是我们创建(或借用)的功能的,我们在原生javascript对象上实现这些功能,以使我们的生活更加轻松.我想将非常有用的原型函数汇总在一起,但只列出在本机对象上实现的那些(即,mootools中的String.implement({...
).
Us Mootoolers and Prototypers (what few are on this site) usually carry around a handy toolbox of functions we have created (or borrowed) that we implement on native javascript objects to make our lives a little easier. I wanted get a list together of very helpful prototyped functions, but only ones that are implemented on native objects (ie String.implement({...
in mootools).
那么,您最喜欢的是什么?
So, what are your favorites?
PS:我同时包含了mootools和prototype,因为为一个库编写的函数很容易移植到另一个库中.
PS: I included both mootools and prototype as a function written for one library is pretty easily ported to the other.
PPS:我知道用于/反对对本机javascript对象进行原型设计的参数,我希望在这里避免进行讨论.
PPS: I know the arguments for/against prototyping native javascript objects, I would prefer to avoid that discussion here.
推荐答案
我继续介绍tj111的内容,这是我的一小部分补充:
I continued on what tj111 started, here's my small addition:
Array.implement({
//calculate the sum of all integers
sum: function() {
var sum = this.reduce(function(a, b) {
return a + b;
});
return sum;
}
});
这篇关于您最喜欢的Mootools/Prototype原生对象原型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!