Mootools 1.4 官方网站的API使用说明存在错误
今天有人在群里问为何给Number用extend扩展的时候总是出错,我记得前几天阅读Moo的源代码时好像发现Number好像是只能用implement来进行扩展,而extend似乎是给Function扩展用的,于是乎查了一下官方文档
http://mootools.net/docs/core/Core/Core
Type method: extend
Adds one or more functions to the type. These are static functions that accept for example other types to parse them into the type, or other utility functions that belong to the certain type.
Syntax:
myType.extend(name, method);
or
myType.extend(methods);
Arguments:
name - (string) The method name.
method - (function) The method function.
or
methods - (object) An object with key-value pairs. The key is the method name, the value is the method function.
Returns:
(object) The type.
Examples:
RegExp.extend('from', function(regexp, flags){
return new RegExp(regexp, flags);
});
Number.extend('parseCurrency', function(currency){
// takes a string and transforms it into a number to
// do certain calculations
});
看到没,这是官方的原文,我测试了一下这段示例,运行结果是错误的,提示说:.parseCurrency is not a function
下边是我的测试代码:
Number.extend('parseCurrency', function(currency){
alert(currency);
});
(1).parseCurrency('ff');
出错提示是:
(1).parseCurrency is not a function
[在這個錯誤中斷] (1).parseCurrency('ff');
通过这个错误就可以知道了,parseCurrency 并非是一个function,于是不死心再次阅读Moo的源码,发现Number确实只能用implement扩展.
由此可见官方的文档是有错漏的.
尽信书不如无书,希望初学Moo的朋友注意一下,不要被其误导了!
分类:
编程
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架