Front End face Test four

Source: Internet
Author: User
Tags processing text browser cache
1, JS array to heavy

Here are three ways to show:

array.prototype.unique1= function () {

var n = []; A new, temporary array

for (var i = 0; i < this.length i++)//traverse the current array

{

If part I of the current array is already saved in a temporary array, skip,

Otherwise push the current item into the temporary array

if (N.indexof (this[i]) = = 1) n.push (this[i));

}

return n;

}

array.prototype.unique2= function ()

{

var n = {},r=[]; n is a hash table and r is a temporary array

for (var i = 0; i < this.length i++)//traverse the current array

{

if (!n[this[i]])//If there is no current item in the hash table

{

N[this[i]] = true; Deposit into a hash table

R.push (This[i]); Push the current item of the current array into a temporary array

}

}

return R;

}

array.prototype.unique3= function ()

{

var n = [This[0]]; Array of results

for (var i = 1; i < this.length i++)//Go through the second item

{

If the first occurrence of the current array in the current array is not the position I,

It means that item I is repetitive and ignored. Otherwise, the result array is stored

if (This.indexof (this[i]) = = i) N.push (This[i]);

}

return n;

}



2. js operation get and set cookies

//Create Cookies

Functionsetcookie (name, value, expires, path, domain, secure) {

var cookietext = encodeuricomponent (name) + ' = ' + encodeuricomponent (value);

if (expires instanceof Date) {

Cookietext + = '; Expires= ' + expires;

}

if (path) {

Cookietext + = '; Expires= ' + expires;

}

if (domain) {

Cookietext + = '; domain= ' + domain;

}

if (secure) {

Cookietext + = '; Secure ';

}

Document.cookie = Cookietext;

}


Get cookies

Functiongetcookie (name) {

var cookiename = encodeuricomponent (name) + ' = ';

var cookiestart =document.cookie.indexof (CookieName);

var cookievalue = null;

if (Cookiestart >-1) {

var cookieend =document.cookie.indexof ('; ', Cookiestart);

if (cookieend = = 1) {

Cookieend = Document.cookie.length;

}

Cookievalue =decodeuricomponent (document.cookie.substring (Cookiestart + cookiename.length,cookieend));

}

return cookievalue;

}


//Delete cookies

Functionunsetcookie (name) {

Document.cookie = name + "=; expires=" + new Date (0);

}


3.ajax have those advantages and disadvantages? How do I solve cross-domain problems?
(Q1)
Advantages:
(1) The user experience is enhanced through asynchronous mode.
(2) optimizes the transmission between the browser and the server, reduces the unnecessary data round-trip, reduces the bandwidth occupation.
(3) Ajax runs on the client, taking on a part of the work that was supposed to be done by the server, reducing the load on the server under large users.
(4) Ajax can achieve dynamic do not refresh (local refresh)
Disadvantages:
(1) Security issues Ajax exposes the details of interacting with the server.
(2) The support for search engines is weaker.
(3) Not easy to debug.
(Q2) Jsonp, iframe, Window.name, Window.postmessage, set up proxy page on the server.
4.JavaScript prototype, prototype chain, what's the feature?
(1) The prototype object is also a normal object, is an object with an implicit __proto__ attribute, the prototype may have its own prototype, if a prototype object's prototype is not NULL, we call it the prototype chain.
(2) A prototype chain is a (limited) object chain consisting of objects used to inherit and share attributes.
the difference between 5.GET and post, and when to use post.
Get: Generally used for information acquisition, using URL to pass parameters, the number of messages sent is also limited, generally 2000 characters
POST: Generally used to modify resources on the server, there is no limit to the information sent.
The Get method needs to use Request.QueryString to get the value of the variable, and the Post method obtains the value of the variable by Request.Form.
That is, get is passed through the address bar to pass the value, and post is by submitting the table forms pass the value.
However, use POST requests in the following situations:
Unable to use cache file (update file or database on server)
Send large amounts of data to the server (POST no data limit)
Post is more stable and reliable than get when sending user input with unknown characters
6. Please explain JavaScript's homology strategy
Concept: Homology policy is an important security metric for client script (especially JavaScript). It was originally from Netscape Navigator2.0 to prevent a document or script from loading from multiple different sources.
The homologous strategy here refers to the same protocol, domain name and port, and the homologous policy is a security protocol.
Refers to a script that can only read properties from Windows and documents from the same source.
Why should there be homology restrictions.
We illustrate: For example, a hacker program, he uses IFRAME to embed the real Bank login page on his page, when you use the real user name, password login, his page can be read through JavaScript to your form in the content of input, so that the user name, The password is easy to get.
7.Flash, Ajax their respective advantages and disadvantages, in the use of how to choose.
Flash is suitable for processing multimedia, vector graphics, access to the machine, CSS, processing text is insufficient, not easy to be searched.
Ajax for CSS, text support is very good, support search, multimedia, vector graphics, machine access is insufficient.
In common: No flush delivery message with the server, user offline and online status, Operation Dom
8. What is closure.
Closures, the official explanation for closures, is that an expression (usually a function) that has many variables and an environment bound to them is also part of the expression. Features of closures:
(1) As a reference to a function variable, when the function returns, it is in the active state.
(2) A closure is when a function returns, a stack area without releasing resources.
Simply put, JavaScript allows the use of intrinsic functions---i.e. function definitions and function expressions in the function body of another function. Furthermore, these internal functions can access all the local variables, arguments, and other internal functions declared in the external function in which they are located. A closure is formed when one of these intrinsic functions is called outside the external function that contains them.
9.javascript How to implement the inheritance, how to avoid the prototype chain above the object sharing
Using the hybrid model of constructors and prototype chains to implement inheritance, avoid object sharing can refer to the classical extend () function, many front-end frameworks are encapsulated, that is, using an empty function as an intermediate variable
10.ajax Process
(1) Create a XMLHttpRequest object, which is to create an asynchronous invocation object.
(2) Create a new HTTP request and specify the method, URL, and authentication information for the HTTP request.
(3) Set up functions that respond to changes in the status of HTTP requests.
(4) Send HTTP request.
(5) Gets the data returned by the asynchronous call.
(6) Local refreshes are implemented using JavaScript and DOM.

11. A page from the input URL to the page load display completed, what happened in the process.
(1) Find browser cache
(2) DNS resolution, lookup of the IP address of the domain name, redirection (301), issue of a second GET request
(3) HTTP protocol session
(4) Client Send header (request header)
(5) Server Feedback header (response header)
(6) The HTML document starts to download
(7) The document tree is established to specify the MIME type of file required by the token request
(8) file display
12. Why change jobs.
13. What are your common development tools and why?
14. What is the understanding of the position of the front-end interface engineer? What is the future of it.
15. The view of overtime.

Overtime is like borrowing money, the principle should be------emergency not to save the poor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.