The most complete set of front-end interview (1)

 

Several ways to create a javascript object

1, the factory pattern

2, model constructor

3, the prototype model

4. Mix and prototype model constructor

5, the dynamic prototype model

6, spurious mode constructor

7, the constructor secure mode

 

Source: www.yinxiangit.com

6 ways inherited javascript

1, the prototype inheritance chain

2, to borrow the constructor inheritance

3, a combination of inherited (+ borrowing prototype configuration)

4, prototypal inheritance

5, Parasitic inheritance

6, parasitic combined inheritance

 

 
    

Asynchronous loading and delayed loading

1.异步加载的方案: 动态插入script标签
2.通过ajax去获取js代码,然后通过eval执行
3.script标签上添加defer或者async属性
4.创建并插入iframe,让它异步执行js
 5.延迟加载:有些 js 代码并不是页面初始化的时候就立刻需要的,而稍后的某些情况才需要的。

Please explain the JavaScript same origin policy.

Concept: homologous strategy is client-side script (especially Javascript) the important security metrics. It comes from the earliest Netscape Navigator2.0, which aims to prevent a document or script loaded from multiple different sources.

Here's same-origin policy means: protocol name, the same port, same origin policy is a security protocol.

It refers to a script read-only properties window and documents from the same source.

Why should there be homologous limit?

We illustrate: for example, a hacker program, he used Iframethe real bank login page embedded on his page, when you use the actual user name, password, you can page through his Javascriptreading to your form inputin the content, so the user name, password easily at hand.

Disadvantages:

Now the site JS will compress some files with strict mode, while others do not. Then these documents could have been strict mode, is  merge after the string on to the middle of the file, not only did not indicate strict mode, but after compression wasted bytes.

 

The difference between GET and POST, when to use POST?
GET:一般用于信息获取,使用URL传递参数,对所发送信息的数量也有限制,一般在2000个字符    
POST:一般用于修改服务器上的资源,对所发送的信息没有限制。    
GET方式需要使用Request.QueryString来取得变量的值,而POST方式通过Request.Form来获取变量的值,也就是说Get是通过地址栏来传值,而Post是通过提交表单来传值。
然而,在以下情况中,请使用 POST 请求:无法使用缓存文件(更新服务器上的文件或数据库)向服务器发送大量数据(POST 没有数据量限制)
发送包含未知字符的用户输入时,POST 比 GET 更稳定也更可靠。

The difference zepto and jq

Same point:

 zepto jQuery is a lightweight alternative. API similar. In jQuery API and commonly used methods is also zepto. zepto also not in some jQuery. 1.zepto files are smaller than jQuery file, lightweight, only a total of more than 8k.

difference:

1. The mobile terminal program: zepto does not support IE browser, which means that IE can still use jQuery, while other browsers can also use the advantages zepto on the file size brings. But they are two of the API is not fully compatible. So use or use caution.

 

Difference in 2.DOM operation: jQuery and zepto will not take effect when adding id.

 

3. The difference between the trigger event: handler in jQuery load event will not be executed; zepto will be executed.

 

4. The difference between an event delegate: Zepto, all click events on the document were commissioned to turn into a queue in sequence. And in jQuery, commissioned a number of events click on the document, click match by selectors, performs delegate event of the corresponding elements.

 

5, the difference between width () and height () of: Zepto determined by box model (box-sizing), () Returns the width assignment with .width, return results or the like by adding border .css ( 'width'); jQuery will ignore box model always returns the width / height content area (not including padding, border).

 

Distinction 6, offset () is: Zepto Back {top, left, width, height}; jQuery returns {width, height}.

 

7, Zepto can not get hidden element width and height, jQuery can.

 

8, Zepto not extend to define the prototype method has jQuery.

 

9, each method Zepto only through the array, can not traverse a JSON object.

 

10, Zepto prop to make use of a method in the operation of dom selected and checked property, in a case where the read attribute value precedence attr. Get Zepto not select element selected option ( 'option [selected]') in a similar manner jQuery $ because the standard properties of the selected property is not css. Should be used $ ( 'option'). Not (function () {return! This.selected}).

 

MVVM interview:

1. Q: What is MVVM?

    A: The view model two-way binding, Model-View-ViewModel shorthand.

      When the data model changes are automatically reflected in the view, and if the view has changed, the same will be reflected in the data model.

2. Q: MVVM advantage of?

    A: 1 low coupling. View (View) Model may be independent of changes and modifications can be bound to a Model different "View", when the Model View change may be constant, when the Model View can change the time constant.

            2. reusability. You can view some of the logic in a Model inside, so many view reuse this view logic.

            3. The independent development. Developers can focus on business logic and developing data (ViewModel), page designers can focus on design.

            4. Test.

3. Q: How to realize his MVVM framework?

 

4. Q: How to realize his MVVM framework?

A: Observer (data monitoring module) which re-cover the get and set methods target object, monitoring changes to the data model, reflecting the view. Parser (parser) used to monitor changes in the view while changing the view reflected in the data model.

 

socket

Two programs on the network via a bidirectional communication to realize the exchange of data, called the connection end of a socket.

 

Establishing a network communications connection to the at least one pair of port number (socket). socket is essentially a programming interface (API), for TCP / IP encapsulation, TCP / IP also provides an interface for programmers to do web development used, this is the Socket programming interface; HTTP is a sedan, provides a packaging or display data specific forms; the Socket engine, provides the ability to network communications.

 

English Socket original meaning is "hole" or "socket." As BSD UNIX process communication mechanism, after taking one meaning. Commonly referred to as "socket" is used to describe IP address and port, a communication link is the handle can be used to enable communication between different virtual machine or on different computers. Hosts on the Internet generally running multiple software services, while providing several services. Each service will open a Socket, and bind to a port, different port corresponding to the different services. Socket as its English intended as a porous plug like. If a host socket covered with a variety of rooms, each socket has a serial number, some outlets provide 220 volts AC, and some provide 110 volts AC, while others provide cable programming. The client software will plug into the socket different numbers, you can get different services.

 

websocket

WebSocket protocol is based on a new network protocol of TCP. It implements the browser and server full-duplex (full-duplex) communication - may be popular explanation for the server sends information to the client.

 

WebSocket is referenced as the first TCP connection, the TCP-based as a placeholder in HTML5 Socket API specification. [1] WebSocket 2011 communication protocol is standardized as IETF RFC 6455, RFC7936 and supplemented Specification

 

What is the WebSocket API?

WebSocket API is the next generation client - server asynchronous communication method. The substitution of a single communication TCP socket, or using ws wss protocol can be used for any client and server programs. WebSocket is currently standardized by the W3C. WebSocket has been 4, Chrome 4, Opera 10.70 and Safari 5 and other browsers support Firefox.

 

The best thing about WebSocket API that the client and server can at any time within a given time range, each push information. WebSocket not limited to Ajax (or XHR) communicate, as Ajax techniques require client sends a request, the server and client can WebSocket push information to each other; the XHR restricted domain, the WebSocket allowed cross-domain communication.

 

Ajax technology that is not very smart way designed to be used. WebSocket is created for the specified target for two-way push messages.

Guess you like

Origin www.cnblogs.com/bingerger/p/11516816.html
Recommended