2016 Ali front-end Development Engineer Pen Test (only questions, no answer):
Http://www.cnblogs.com/sdgf/archive/2015/08/18/4740698.html
Question 6th: Please fill in the answer in ____, so as to achieve the requirements of the topic
var arr = [1, 2, 3, 4, 5];var result = Arr.sort (_______________________________). Join ("+"); Console.log (result);
answer : In sorting, if you need to sort by a certain rule, you can add a custom function:
If from large to small arrange: function (A, b) {return b-a;};
If you are from small to large: function (A, b) {return a-A;};
A more detailed description of the sort method for array:
Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
Question 7th: Turning a literal object into an instance of a class
function Type () {}var a = {};______________//a instanceof Type = = = True
answer : You need to modify the type of a in this topic, so we need to know: instanceof operator code
function instance_of (L, R) {//l represents the left expression, R represents the right expression var O = R.prototype; The display prototype L = l.__proto__ of R is taken ; Take the implicit prototype of L while (true) { if (L = = = null) return false; if (o = = = L)//Here Focus: When O is strictly equal to L, returns true to return True ; L = l.__proto__; } }
Detailed Description: http://www.ibm.com/developerworks/cn/web/1306_jiangjj_jsinstanceof/
Knowing what's above, we learned that the insanceof decision is based on whether the __proto__ of the instance object is strictly equivalent to the prototype property of the constructor that created the object. That
The instance object. __proto__ = = = constructor. prototype.
So the solution to this problem is to add the __proto__ attribute to a and make it equal to the prototype property of type.
Code Implementation : a.__proto__ = Type.prototype;
Question 8th: Add the following function to determine that p is an array
function IsArray (p) { return object.prototype._____.apply (p) = = = ' _____ '; }
Answer: the question needs to be understood: about the use of the Object.prototype.toString () method:
Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
So the solution to this problem is: toString [object Array]
The above content is purely personal opinion, welcome to correct the mistake, I am also JS beginner.
Front-end test-2016 Ali front-end Development Engineer Pen Question 6,7,8 problem solution