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

}

时间: 2024-10-13 12:54:31

js题集20的相关文章

js题集29--部分题目在线答题链接地址

1.http://davidshariff.com/js-quiz/  ---难度正常 2.http://perfectionkills.com/javascript-quiz/ --略虐心 3.http://perfectionkills.com/javascript-quiz-es6/ --没看过es6的就算了吧. 4.http://madebyknight.com/javascript-scope/  --基础题. 5.http://www.w3schools.com/js/js_quiz

js题集23

1.实现函数--defaultArguments 功能如下: function add(a,b) { return a+b;}; var add_ = defaultArguments(add,{b:9}); add_(10); // returns 19 add_(10,7); // returns 17 add_(); // returns NaN add_ = defaultArguments(add_,{b:3, a:2}); add_(10); // returns 13 now ad

js题集8

1. var f = true; if (f === true) { var a = 10; } function fn() { var b = 20; c = 30; } fn(); console.log(a); console.log(b); console.log(c); 2. var x = 1; var y = 0; var z = 0; function add(n){n=n+1;} y = add(x); function add(n){n=n+3;} z = add(x); 3

js题集7

1. []==[] 答案:false. 数组,在 Javascript 中是对象,对象使用 == 比较都是比较的引用. 简单的说,就是,如果是同一个对象,就相等,如果不是同一个对象,就不等. 每次使用 [] 都是新建一个数组对象,所以 [] == [] 这个语句里建了两个数据对象,它们不等. 2. [3.toString(),3..toString(),3...toString()] 答案:error,"3",error Number中的toString(a),能够将数值转化成为a进制

js题集6

1. function() { var a = 10; if(a > 5) { a = 7; } alert(a); } 2. function() { if(true) { var a = 5; } alert(a); } 3. var a = 5; function first() { a = 6; } function second() { alert(a); } 按顺序执行函数. 4. var a = 5; function() { var a = 7; alert(a); } 5. v

js题集19

1.实现斐波那契数列.达到题目中的效果.不知道斐波那契数列是啥的请自行百度. function fibonacci(){ } var f=fibonacci(); for(var i=0;i<10;i++){ console.log(f()); } //output:按顺序输出斐波那契数列的数字. eg: 1 2 3 5 8 13 21 34 55 89

js题集27--数组拼接写法

1.能FQ的人类 可以参考如下链接(遍历过十几个相关的文章 觉得这个算不错的) https://davidwalsh.name/combining-js-arrays 2.不能FQ的可以参考 简略翻译.. 对于数组 var a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]; var b = [ "foo", "bar", "baz", "bam", "bun", "fun&quo

js题集22

1.实现warp function speak(name){ return "Hello " + name; } speak = speak.wrap(function(original, yourName, myName){ greeting = original(yourName); return greeting + ", my name is " + myName; }) var greeting = speak("Mary", &quo

js题集5

1. var foo = function foo() { console.log(foo === foo); }; foo(); 2. Number("1") - 1 == 0; 3. (true + false) > 2 + true; 4. function bar() { return foo; foo = 10; function foo() {} var foo = '11'; } alert(typeof bar()); 5. "1" - - &