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. WCF依赖注入和抽象工厂
- 7. Grails依赖注入和工厂
- 8. 依赖注入和/或工厂模式
- 9. Angular.js - Javascript依赖注入
- 10. AngularJS - 在服务,工厂,过滤器等依赖注入
- 11. 模型工厂内的依赖注入
- 12. 工厂模式在依赖注入
- 13. PHP工厂模式依赖注入
- 14. 依赖注入功能与工厂(AngularJS)
- 15. 依赖注入容器 - 工厂模式
- 16. 通用接口依赖注入工厂
- 17. 服务层依赖注入
- 18. 依赖注入服务
- 19. osgi依赖注入服务
- 20. 将依赖注入与工厂模式混合很好吗?
- 21. 在ASP.NET中使用依赖注入和工厂模式传递服务
- 22. 什么是依赖注入?
- 23. 你如何使用依赖性服务和依赖注入?
- 24. RAD:依赖注入 - 好处?
- 25. 在依赖注入中使用策略和工厂模式
- 26. 抽象工厂和统一依赖注入
- 27. 需要工厂和依赖注入帮助
- 28. 为什么依赖项注入在我的CF工厂对象中失败?
- 29. 依赖注入或服务位置?
- 30. Symfony FOSRestController作为服务(依赖注入)
希望帮助: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