js题集20
Posted tong24
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js题集20相关的知识,希望对你有一定的参考价值。
1.实现如下代码功能
var deps = {
‘dep1‘: function () {return ‘this is dep1‘;},
‘dep2‘: function () {return ‘this is dep2‘;},
‘dep3‘: function () {return ‘this is dep3‘;},
‘dep4‘: function () {return ‘this is dep4‘;}
};
var di = new DI(deps);
var myFunc = di.inject(function (dep3, dep1, dep2) {
return [dep1(), dep2(), dep3()].join(‘ -> ‘);
});
myFunc();// ‘this is dep1 -> this is dep2 -> this is dep3‘);
=============your code==============
/**
* Constructor DependencyInjector
* @param {Object} - object with dependencies
*/
var DI = function (dependency) {
this.dependency = dependency;
};
// Should return new function with resolved dependencies
DI.prototype.inject = function (func) {
// Your code goes here
}
以上是关于js题集20的主要内容,如果未能解决你的问题,请参考以下文章