Giter Club home page Giter Club logo

Comments (6)

BigKongfuPanda avatar BigKongfuPanda commented on June 23, 2024 2

楼主,我个人觉得你这篇文章里面的代码有些地方不太好。

  1. 不应该用 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; 
}; /
  1. 感觉直接将一个变量的类型从基本类型变为引用类型,不太好。比如上面的代码中,params[i] 本来是函数名,为字符串,而你在进行 params[i] = services[params[i]]; 之后,将 params[i] 变为了 function ,这个地方,你完全可以在定义一个新的数组来存放 services[params[i]] 的值。

以上只是个人的看法哈。

from blog.

nikolausliu avatar nikolausliu commented on June 23, 2024 1

不穿格子衫的程序员正在角落瑟瑟发抖:)

from blog.

yanlee26 avatar yanlee26 commented on June 23, 2024

可以顺带讲解一下ng或vue的依赖注入机制吗?

from blog.

Aaaaaaaty avatar Aaaaaaaty commented on June 23, 2024

@nikolausliu 我其实也不穿哈哈哈

from blog.

Aaaaaaaty avatar Aaaaaaaty commented on June 23, 2024

@yanlee26 我其实推荐了这篇文章 http://yanhaijing.com/javascript/2014/01/24/dependency-injection-in-javascript/ 这个里面就是模仿了ng的依赖注入的形式,虽然不是其内部源码讲解但是思路还是有的

from blog.

JackZong avatar JackZong commented on June 23, 2024

nice

from blog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.