JS Object-oriented interview data

Source: Internet
Author: User
Tags what file type hosting

JS Object-oriented interview data

1 tell me about your understanding of closures.

Closures are used primarily to design private methods and variables. The advantage of closure is to avoid the pollution of global variables, the disadvantage is that the closure will be resident memory, will increase memory usage, improper use can easily cause memory leaks.

Closures have three properties:

1. Function nesting functions

2. External parameters and variables can be referenced inside the function

3. Parameters and variables are not recycled by the garbage collection mechanism

2. What are the differences and effects of call () and. Apply ()?

Function: Dynamically alters the operating environment of a method of a class.

1, Call,apply is a method of function.prototype, it is implemented within the JavaScript engine, because it belongs to Function.prototype, so each function object instance (that is, each method) Have call,apply properties. Since as a property of the method, the use of them is of course for the method, and these two methods are easy to confuse, because they work the same way, just different ways of using.

2, Syntax: Foo.call (this, arg1,arg2,arg3) = = Foo.apply (this, arguments) = = This.foo (arg1, arg2, ARG3);

3, the same point: two methods produce the same effect.

4, different points: The method passed different parameters.

3, how to implement the inheritance in JavaScript, how to avoid the object sharing above the prototype chain

with the combination of the constructor and the prototype chain to implement inheritance, to avoid object sharing can refer to the classic extend () function, many front-end frameworks are encapsulated, is to use an empty function as an intermediate variable

4, JavaScript prototype, prototype chain? What are the characteristics?

The prototype object is also a normal object, is an object with an implicit __proto__ property, the prototype may have its own prototype, if the prototype of a prototype object is not NULL, we call it a prototype chain. *

A prototype chain is a (finite) object chain of objects that are used to inherit and share attributes.

5. How do you optimize your website's files and resources?

The expected solutions include:

file Merge

file minimization /file compression

Use CDN Hosting

Cache Usage (multiple domain names to provide caching)

other

6, please say three ways to reduce the page load time.

1. Picture optimization

2. Image format Selection (GIF: Provides less color and can be used in some places where color requirements are not high)

3. Optimize CSS (compress merge CSS, such as margin-top,margin-left ...)

4. The URL followed by a slash (such as the www.campr.com/directory, will determine the "directory is what file type, or directory.") )

5. Mark Height and width (if the browser does not find these two parameters, it needs to download the picture while calculating the size, if the picture is many, the browser needs to constantly adjust the page. This affects not only speed, but also the browsing experience.

When the browser knows the height and width parameters, even if the picture is temporarily unable to display, the page will free up the picture, and then continue to load the later content. The loading time is fast and the browsing experience is better. )

6. Reduce HTTP requests (merge files, merge pictures).

7.6 Methods of JavaScript inheritance

1, prototype chain inheritance

2, borrowing constructor inheritance

3, combination inheritance (prototype + borrowing constructs)

4, prototype-type inheritance

5, parasitic inheritance

6, parasitic combined inheritance

Several ways to create JavaScript objects

1, Factory mode

2, constructor mode

3, prototype mode

4, mixed constructors and prototype patterns

5, dynamic prototype mode

6, parasitic constructor mode

7, secure constructor mode

8. What are your performance optimization methods?

(see Yahoo 14 Performance Optimization principles for details).

(1) reduce the number of HTTP requests: CSS Sprites, JS, CSS source compression, picture size control appropriate; web Gzip,cdn hosting, data caching, image server.

(2) front-end template js+ data, reduce the bandwidth wasted due to HTML tags, front-end with variables to save AJAX request results, each operation of local variables, no request, reduce the number of requests

(3) using innerHTML instead of DOM operation, reduce DOM operation times and optimize JavaScript performance.

(4) When you need to set a lot of styles, set classname instead of manipulating the style directly.

(5) Reduce the use of global variables, cache DOM node lookup results. Reduce IO read operations.

(6) Avoid using CSS expression (CSS expressions), also known as dynamic properties.

(7) picture preload, put the style sheet on top, put the script at the bottom ? Plus time stamp.

9 How do you manage your project at ordinary times?

1 The advance team must determine the global style (GLOBE.CSS), encoding mode (UTF-8), etc.;

2 Writing habits must be consistent (for example, the use of inheritance, the single style is written in one line);

3 Dimension style writer, each module is labeled in time (the place where the key style is called);

4 pages for labeling (e.g., page module start and end);

5 css is stored in parallel with the HTML sub-folder, the name is unified (such as STYLE.CSS);

6 JS Sub-folder for the name of the JS function of the English translation.

10. What is a closure, what happens when a closure causes memory overflow?

in direct terms, closures are functions that can read the variables inside other functions, In JavaScript, only sub-functions within a function can read local variables, so the closure is simply understood as "a function defined inside a function", so in essence, a closure is a bridge that connects the inside of the function to the outside of the function. The maximum use of closures is two, one is to read the variables inside the function, and the other is to keep the values of these variables in memory at all times.

There are two reasons that closures cause memory leaks:

1. Circular references cause a memory leak

2. Memory leaks caused by external function calls

Avoid memory leaks

1. Breaking circular references

2. Add another closure

3. Avoid closing the package itself

solution closure: run out of direct ==null;

JS Object-oriented interview data

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.