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