1
A
回答
0
这些概念是JavaScript核心的一部分。
RegExp
是工厂:
console.log(RegExp("[0-9]"));
console.log(RegExp("[a-z]"));
console.log(RegExp("[A-Z]"));
console.log(RegExp("[0-9a-zA-Z]"));
Math
是服务:
console.log(Math.PI);
console.log(Math.round(Math.PI));
console.log(Number(Math.random() * 1000).toFixed());
console.log(Number(Math.random() * 10).toPrecision(2));
console.log(Math.floor(Math.random() * 20) + 1);
call
和apply
是依赖注入:
"use strict";
var foo = {
min: function min(array) {
return Math.min.apply(Math, array);
},
max: function max(array) {
return Math.max.apply(Math, array);
}
};
var bar = foo.min([1,2,3]);
var baz = foo.max([1,2,3]);
console.log("bar: " + bar);
console.log("baz: " + baz);
参考
相关问题
- 1. Zend2依赖注入工厂服务
- 2. 依赖注入和工厂
- 3. 为什么依赖注入比使用工厂更好?
- 4. 依赖注入与工厂
- 5. 依赖注入和/或工厂模式
- 6. AngularJS - 在服务,工厂,过滤器等依赖注入
- 7. 模型工厂内的依赖注入
- 8. PHP工厂模式依赖注入
- 9. 工厂模式在依赖注入
- 10. 通用接口依赖注入工厂
- 11. 服务层依赖注入
- 12. 依赖注入服务
- 13. 将依赖注入与工厂模式混合很好吗?
- 14. 在ASP.NET中使用依赖注入和工厂模式传递服务
- 15. 什么是依赖注入?
- 16. RAD:依赖注入 - 好处?
- 17. 需要工厂和依赖注入帮助
- 18. 在依赖注入中使用策略和工厂模式
- 19. 为什么依赖项注入在我的CF工厂对象中失败?
- 20. 服务定位与依赖注入
- 21. 服务之外的Grails依赖注入?
- 22. Symfony FOSRestController作为服务(依赖注入)
- 23. WCF服务中的依赖注入
- 24. 动态更新依赖注入服务
- 25. Angular 2服务依赖注入问题
- 26. Web服务的依赖注入?
- 27. 工厂女生依赖工厂
- 28. 依赖注入不工作
- 29. 依赖注入 - 我错过了什么?
- 30. 什么是应用依赖注入
希望帮助:http://stackoverflow.com/questions/15666048/service-vs-provider -vs-factory,http://stackoverflow.com/questions/13762228/confused-ab出服务-VS-工厂/ 13763886#13763886 – 2014-09-20 17:17:10