Comments (6)
楼主,我个人觉得你这篇文章里面的代码有些地方不太好。
- 不应该用
for in
来遍历数组。在 通过依赖项来查询对应服务 中,参数params
为数组对吧,for in
循环数组的下标之后,下标 i 就从 number 类型变为了 string 类型了,这是使用for in
来遍历数组的弊端,所以应该避免这么操作。
//简易实现
setFuncParams = function (params) {
for (var i in params) {
params[i] = services[params[i]];
}
return params;
}; /
- 感觉直接将一个变量的类型从基本类型变为引用类型,不太好。比如上面的代码中,params[i] 本来是函数名,为字符串,而你在进行
params[i] = services[params[i]];
之后,将 params[i] 变为了 function ,这个地方,你完全可以在定义一个新的数组来存放services[params[i]]
的值。
以上只是个人的看法哈。
from blog.
不穿格子衫的程序员正在角落瑟瑟发抖:)
from blog.
可以顺带讲解一下ng或vue的依赖注入机制吗?
from blog.
@nikolausliu 我其实也不穿哈哈哈
from blog.
@yanlee26 我其实推荐了这篇文章 http://yanhaijing.com/javascript/2014/01/24/dependency-injection-in-javascript/ 这个里面就是模仿了ng的依赖注入的形式,虽然不是其内部源码讲解但是思路还是有的
from blog.
nice
from blog.
Related Issues (20)
- 用canvas实现视频播放与弹幕功能 HOT 5
- 基于canvas使用贝塞尔曲线平滑拟合折线段 HOT 8
- 基于canvas使用粒子拼出你想要的文字 HOT 7
- 11
- 基于canvas使用粒子拼出你想要的文字[2]——粒子的动画效果
- bezierMaker.js——N阶贝塞尔曲线生成器 HOT 6
- Canvas进阶——贝塞尔公式推导与物体跟随复杂曲线的轨迹运动 HOT 1
- canvas进阶——实现静态图像的变形并合成动态效果 HOT 6
- 基于JavaScript求解八数码的路径搜索并生成动画效果 HOT 4
- 记一次“失利后”经过半年准备通过阿里社招的经历与感悟 HOT 25
- aaa HOT 1
- 由一个“bug”到鲜为人知的jQuery.cssHooks
- 结合kmp算法的匹配动画浅析其基本** HOT 3
- 有掘金地址吗 HOT 1
- 你好 我想请问下 我根据您写的绘制贝塞尔曲线,拿到的[x,y]的数据 如何让物体跟随运动
- 淘系技术部-用户增长团队内推指南
- 阿里面试评级 HOT 2
- 怎么更好的阅读博客?
- 请问一下基于JS的深度优先搜索生成动画怎么解啊
- 回顾从学生到阿里,经历的几次蜕变 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.