So there is no concept of class in JavaScript. It is important to understand that many JavaScript tutorials are designed to make readers understand more easily by applying the concepts in their commonly used class patterns, which in turn makes them ambiguous.
Advanced Segment Code,
Copy Code code as follows:
function Employee () {
This.name= "";
This.dept= "";
}
employee.prototype={
New
New object is created with the constructor function.
Define class
var person = function (firstName) {
this.firstname = firstName;
};
Define method
Person.prototype.sayHello = function () {
console.log ("Hello, I ' m" + this.firstname);
Instance Object
var person1 = new Person ("Alice");
Object Invocation Method
Person1.sayhello ();//Logs "Hello, I ' m Al
1. Official feature236:parser API for Nashorn292:implement Selected ECMAScript 6 Features in Nashorn2. Instructions for useThe Nashorn project has been improved in JDK 9, which provides the lightweight Javascript runtime for Java. The Nashorn project follows the Netscape Rhino project to implement a high-performance but lightweight Javascript runtime in Java. The Nashorn project allows Java applications to
Let's take a look at some examples first
function Me (name,age,job) {
this.name = name;
This.age = age;
This.job = job;
}
What is the difference between the following two kinds of instantiated object methods?
var mefun1 = new Me (' Fei ', ' m ', ' it ');
var mefun2 = Me (' Fei ', ' m ', ' it ');
To put it simply,
The first is a constructor that calls the constructor function with the
ObjectiveRecently, learning the essence of JavaScript language, I feel very well written. So here is a summary. How does a method create a process using new, and how does a function statement internally execute it?In addition to the process of learning, constantly referencing ECMAScript API, can also understand a lot of things. ECMAScript API:W3C Reference Address: http://www.w3school.com.cn/js/pro_js_funct
This method is not the author's original, the author is only on the basis of predecessors, to summarize, to obtain a concise and practical JavaScript inheritance method.Traditional JavaScript inheritance is based on the prototype prototype chain, and requires a lot of new operations, the code is not concise, the readability is not very strong, it seems to be vuln
1. Always remember to use the New keyword to execute the constructor.As mentioned earlier, you can use constructors to create JavaScript objects that use the New keyword when used, but what if you forget to write the new keyword? In fact, this function will still be executed, there is no syntax error, but there is a lo
The first thing to be clear is that the constructor in JavaScript does not need to have a return value, which is similar to Java. It can be considered that the most significant difference between a constructor and a normal function is that there is no return statement in the constructor, the normal function can have a return statement, the constructor uses the This keyword to define member variables and member methods, and normal functions do not use
just milliseconds after the download have finished, and results in pages loading as Mu Ch as 10% faster. It ' s particularly effective on large scripts and slow network connections.The script stream optimizes the parsing of the JS file. Starting with version 42, at the beginning of the download, Chrome parses asynchronous and deferred scripts on a separate thread. This means that when the download is completed for 1 per thousand seconds, the parsing is complete.Code caching is another
Original: Get time in JavaScript new date () detail
17javaScript Tutorial Series: JS get time new Date () detailed introductionJS Time Newdate () character type conversionvar mydate = new Date ();Mydate.getyear (); Get Current year (2-bit)Mydate.getfullyear (); Get full year (4-bit, 1970-????)Mydate.getmonth (); Get Cu
JavaScript Strict mode: run under strict conditionsHow to: Add ' use strict ' command browser support at top of JavaScript (Internet Explore + +, Firefox 4+, Chrome 13+, Safari 5.1+, Opera 12+)What are the benefits of strict mode?1, improve the situation of error;2, improve the compiler efficiency, increase the speed of the operation;3. Pave the new version of
This method is not original, the author only on the basis of predecessors, summed up a concise and practical JavaScript inheritance method.
Traditional JavaScript inheritance is based on the prototype prototype chain, and requires a lot of new operations, the code is not concise, readability is not very strong, seemingly also vulnerable to the prototype chain po
the default event of the A tag is fired, and a new page is opened. Note: If you need to open a new window, you cannot use return False,e.preventdefault () in the Click event, or the statement that interrupts the default event. 2, other situation: if there is no a tag to open the page, then we create a new a tag out, and then simulate this a-tag click eventjquery
The same language JavaScript, in different browsers, there is a language compatibility problem, essentially because different browsers are supported language standards and implementation of the differences. This article will create a Date object based on the new date to parse the problem.
1. The problem of the proposed, start time and end time space can not correctly pass the value
In the page, we used a
In JavaScript, this is defined when created. What does this sentence mean?
function Foo () {
this.name = ' Peter ';
}
Foo ();
Console.log (name);//this is the global object when it is created, so the name here is Peter;
So what's different about adding a keyword new?
Let's say varobj = new Foo ();
In JavaScript, the
Javascript-I love a programming language, but the name is really bad. This program does not actually have any relationship with Java. I can confirm that. Now that ECMA is working on designing the next version of JavaScript (the code name is ES4), you should give JavaScript a new name.
How do you get a loud name? Altho
() a.prototype=New B (); Console.log (a); Console.log (a.prototype); Console.log (a.__proto__); Console.log (a.constructor); // a.show (); a.prototype.show (); A.show ();Output:functionA (name) {//Use a.prototype=new B () when a property is not changed This. Name= "A"; } b {Name:"B", Show:function}//But the prototype of a is completely covered by the This property and t
4 issues related to this, new, call and apply The principle of this pointer is a very complicated question, and if we illustrate this from the implementation mechanism of this in JavaScript, many friends may become more and more confused, so this article is going to change the idea of the this pointer from an application perspective, It is more realistic to understand this pointer from this perspective. Let
JavaScript opens new Window methodwindow.open (' http://www.onesheng.cn ');"1, the most basic popup window code"In fact, the code is very simple:。 Into this good habit ah.window.open (' smsyun.html ') is used to control the pop-up of a new window page.html, if page.html is not in the same path as the main window,The path, absolute path (http://www.onesheng.cn), a
var a = a ();
var B = A ();
Console.log (a.age);
Console.log (b.age);
B.age =;
Console.log (a.age);
Console.log (B.age);
So how do we solve this problem, and then we'll talk about the second way, and it's the way jquery uses it.
The second way
var A = function () {return
new A.prototype.init ();//①
}
a.prototype = {
init:function () {
this.age = N;
Console.log (this);
return this;
},
age:100
}
A.prototype.init.pro
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.