It is not easy to find a good JavaScript resource, and it also challenging to come up with the proper set of questions to determine whether the candidate be a good match. I know a lot of colleagues that simply ask very generic or theoretical questions during the interview process, but for me the main indication is the person’s ability to produce the good quality code under short period of time. My interview usually takes around 45 minutes where interviewee writes a code over skype sharing. One of the typical tasks I give is to create a tabview component + several other basic components inside of the TabView class. I prefer candidates to use native JavaScript to see if they know fundamentals rather then simply relying on frameworks. Being expert in framework is enough for website developer, but for any serious Single page app the core JS skills are critical.
Anyways, here’ the good enough answer to my TabView task developed by me in 25 minutes.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<html>
<style>
#tabs li{display: inline;list-style-type: none;padding-right: 20px;}
#tabs li a { color: black; background: white; text-decoration: none; }
#tabs li a:hover { background: #ccc; }
</style>
<ul id="tabs">
<li><a href="graph" id="0">Graph</a></li>
<li><a href="list" id="1">List</a></li>
<li><a href="tree" id="2">Tree</a></li>
</ul>
<div id="graph"></div>
<div id="list"></div>
<div id="tree"></div>
<script>
function bind(scope, fn) {
return function () {
fn.apply(scope, arguments);
};
}
function TabView(el, options) {
this.el = document.querySelector(el);
this.options = options || {};
this.render();
this.bindUI();
}
TabView.prototype = {
render: function(){
this.clear();
this.options.tabContents[this.options.activeTab].render();
},
clear: function(){
this.options.tabContents[this.options.activeTab].el.innerHTML = "";
},
bindUI: function(e)
{
this.el.addEventListener("click", bind(this, this._handleTabClicked), false);
},
_handleTabClicked: function(evt){
evt.preventDefault();
var target = evt.target,
targetId = evt.target.id;
this.options.activeTab = parseInt(targetId, 10);
this.render();
}
};
function Graph(){
this.el = document.getElementById("list");
this.render = function(){
this.el.innerHTML = "Graph";
};
}
function List(){
this.el = document.getElementById("list");
this.render = function(){
this.el.innerHTML = "List";
};
}
function Tree(){
this.el = document.getElementById("list");
this.render = function(){
this.el.innerHTML = "Tree";
};
}
var tabView = new TabView('#tabs', {
activeTab: 1,
tabContents: [ new Graph(), new List(), new Tree() ]
});
</script>
</html> |