首页 > 代码库 > js题集20

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