Want to know object oriented javascript interview questions? we have a huge selection of object oriented javascript interview questions information on alibabacloud.com
The factory mode and constructor mode are introduced in javaScript object-oriented design and Javascript object-oriented design, as well as their advantages and disadvantages, today, we will continue to explain the prototype mode.
This section describes several key words about object-oriented: encapsulation, inheritance, and polymorphism. It expands JavaScript object-oriented key words about object-oriented: enca
This section describes the private and public members of JavaScript. Although JavaScript does not have private and public keywords, it is still the same sentence-as developers, we need to have an object-oriented idea! The last two sections talk about the JavaScript
people who pass technical interviews are much more likely to be excellent programmers than those who cannot pass technical interviews.
Finally, I would like to say that I will not pass them out because the applicant answered three or two wrong questions or did not answer them as expected. However, if the other party cannot answer most of the questions, I will give him a red light!
The following seven
a desire to greet the creator of the code. Yes, the third function directly triggers my decision to use object oriented.
In fact, I can completely transform the third function into the following.
Copy Code code as follows:
function append (obj)
{
var a=document.craeteelement ("a");
a.title= "Hello";
a.href= "javascript:void (0);";
A.innerhtml=a.title;
A.click=function () {create
The full use of object-oriented design in JS can greatly improve code reuse, reduce the coupling between modules, better logical layering and parallel development. Here are a few steps to simply talk about my understanding.
data type and Packing classPacking class ... Type name ... Common values ... Classification
Number ... number ...... 123.123. ... Basic data types
Boolean ... Boolean ... true, false
calling o. method (), we can see that the method defined on the parent class prototype will not inherit from the quilt class.
By calling o. method3 (), we can see that the instance methods defined in the subclass cannot access the private instance members defined in the parent class.
Finally, we can see from the results of the call to subClass. staticMethod () that static members will not be inherited.
Finally, this example does not show that multiple inheritance can be implemented by calling t
private method.
3. The genuine privatization of members through closures. For friends who are unfamiliar with scopes and nested functions in the concept of closures, you can refer to the article "One of the object-oriented JavaScript (beginner JavaScript)", which is not discussed in detail here.
Copy Code code
prototype methods are added to the sub-class.Instance1.colors.push (' black '); Console.log (instance1.colors); // [' Red ', ' blue ', ' green ', ' black '] // [' Red ', ' blue ', ' green ']instance1.getname (); // CSSbook instance2.gettime (); // -Note: A subclass that wants to add a prototype method must pass a prototype object, one way to add it through the form of a point syntax, or it will be directly assigned to an
To create an object with the new object ()
There are several ways to create objects in JavaScript, and different methods can be used on different occasions. The simplest is to use the new operator, for example:
Copy Code code as follows:
We defined the object of person in this example, and then adde
Because most of the project JAVASCRIPT,CSS client work is another colleague in charge, the colleague and special busy can not be reconstructed, the boss also just make suggestions did not immediately implement refactoring. But I've also changed a little bit of client bugs in the last few days, it is true that the code is a little foggy, I do not know which mountain, easy to move code, so I started to tinker with the love and hate of
a behavior, once the behavior changes, there is no need to modify many classes, just modify this behavior. AOP is this decentralized programming approach that encapsulates "focus" in "facets"2) control reversal IOC (inversion of control) controls refers to dependencies between program-related classes. In traditional conceptual design, it is usually the caller who creates an instance of the callee, in Spring, the work of creating the callee is no longer done by the caller, but by the The Spring
Because of talents, I had to extract some of the content from the Javascript Advanced Program, which was also my reading notes. Because of the Javascript object-oriented mechanism and its importance, and the content is very numerous, here on the chapter by section.
The object
In object-oriented languages, overloading is an important feature, while JavaScript, a self-proclaimed object-oriented language, does not directly provide overload functions. Let me define it as follows:
The Code is as follows:
Function getDate (){.....}Function getDate
Javascript does not have the namespace concept, but to embody the object-oriented thinking, there should be a namespace, just like the package in java ,. the namespace in. net is used to prevent class name conflicts. The same class name does not conflict as long as it belongs to different namespaces. The simplest way to create a namespace is:
The Code is as fol
In small projects for JavaScript use, just write a few function on the line. But in large projects, especially in the development of the pursuit of a good user experience of the site, such as SNS, will use a lot of javascrpt, sometimes the workload of JavaScript than C #, then write a bunch of function, it will appear very messy, messy, even the naming conflict, Management and maintenance are all very troub
There is no concept of namespaces in JavaScript, but to embody object-oriented thinking,
There should be a namespace, just like the namespace in Package,.net in Java,
The main function is to prevent class name conflicts, the same class name as long as the different namespaces, will not conflict.
The easiest way to create namespaces:
Copy Code code as follo
1 How to create an object:
1. Use constructor, for example:
var obj = new Object ()//var can be omitted
var obj = new Date ()
2. Use object literal value (literals),For example:
Program code
var obj = "123"//Create a String object
var obj =/^abc$///Create a RegExp object
This section describes the private and public members of JavaScript. Although JavaScript does not have private and public keywords, it is still the same sentence-as developers, we need to have an object-oriented idea! In fact, it is very simple. I believe you will be clear at a glance after reading the following code a
Introduction to javascript Object-Oriented Programming and Object-Oriented Programming
The ECMA-262 defines an object as a collection of unordered properties that can contain basic values, objects, or functions"
The simplest way t
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.