Javascript: a deep understanding of basic Javascript knowledge and a deep understanding of javascript

Source: Internet
Author: User
Tags hasownproperty

Javascript: a deep understanding of basic Javascript knowledge and a deep understanding of javascript
The eval global function is shown in the loader of dojo as the next function.

Var eval _ = new Function ('Return eval (arguments [0]); '); // The Function runs in the top-level scope, but the running efficiency is slower, however, this method does not pollute global variables and calls the top-level scope eval ('var I = 100; '); alert (I ); // 100 eval _ ('var B = 100'); // alert (B); // error, B does not define var where = 'I am abroad '; // global scope where function test () {var where = ' '; // closure where eval _ ('alert (where )'); // I am abroad, global scope eval ('alert (where) '); // I am in China, partial full use of domain windows. eval ('alert (where) '); // I'm in IE6/7/8 abroad. I am in China and will not use a global scope. execScript} test () can be used ()

The kernal module of dojo also has an eval function. The code and explanation are as follows:
(Function ("d", "d. eval = function () {return d. global. eval? D. global. eval (arguments [0]): eval (arguments [0]);} ") (dojo);/* = dojo. eval = function (scriptText) {// try to execute the corner string (scriptText) in the global scope. Except for IE, other browsers can correctly execute this string in the global scope, execute dojo. eval ('var pi = 100'); alert (pi) // pi undefined; you need to execute the global variable dojo in IE. eval ("window. pi = 3.14 "); To execute global variables in IE, execScript can only be used, but it does not return a value and cannot terminate the execution */

For image attribute detection and enumeration Javascript, the following methods are used for Attribute Detection:
  • In operator. If the object has its own property or the inherited property contains the property to be detected, true, "toString" in {x: 'hello'} // true is returned;
  • HasOwnProperty () checks whether the given name is a property of the object. If yes, true is returned. If yes, false is returned for the inherited property;
  • PropertyIsEnumerable () is an enhanced version of hasOwnProperty. It detects its own attributes and can be enumerated.
  • For/in Enumeration The enumerated attributes of the image include (self-owned attributes and inheritance attributes), not enumeration built-in methods ("toString"), but self-rewriting built-in methods, enumerable
  • Built-in attributes such as toString, toLocaleString, and valueOf cannot be enumerated. prototype. propertyIsEnumerable ('tostring') returns true, but the toString method defined by the Code can be enumerated (most of the attributes defined by the Code can be enumerated), but before IE6, the built-in method that you have redefined cannot be enumerated. you can use the following code to adjust
/* Define an extension function to copy the second and later parameters to the first parameter. However, in IE, there is a bug, it is the built-in method defined by the user (for example, if the toString method is defined in the second parameter pair image, the for/in method in IE6 will not be enumerated to the toString method, this user-defined method will not be copied. Therefore, when the code needs to show multiple objects, the attribute level of the right parameter is higher */var extend = (function () {for (var p in {toString: null}) {return function (o) {for (var I = 1, len = arguments. length; I <len; I ++) {var source = arguments [I]; for (var prop in source) o [prop] = source [prop];} return o ;}} // IE 6 var protoprops = ['tostring', 'tolocalstring', 'valueof ', 'hasownproperties', 'isprototype', 'constructor ', 'propertyisenumerable']; return function (o) {for (var I = 1, len = arguments. length; I <len; I ++) {var source = arguments [I]; for (var prop in source) o [prop] = source [prop]; for (var j = 0; j <protoprops. legnth; j ++) {prop = protoprops [j]; if (source. hasOwnProperty (prop) o [prop] = source [prop] ;}} return o ;}})()



What basic knowledge should be learned before learning Javascript?

Javascript is used in Web pages, so some Web Page code is designed-that is, the HTML language,
In addition, JavaScript also has its own syntax, which is similar to the basic syntax of general programming languages. The JavaScript syntax should be simplified by the java language. In addition, the code written in java is quite similar to the code written in C language. I only learned C language before I learned JavaScript.

Maybe you need to look at the basic syntax of C language or Java. Maybe the syntax in JavaScript is not very clear.

Basic javascript knowledge

You should understand JAVA well ~~

Objects can be hierarchical ~~~

Public class test {
Public string a = "";
}
Test t1 = new test ();
Test1.a = "B ";

It means something similar to the above ~~

Document is implemented by DOM ~~ What I said upstairs is wrong. javascript does not provide DOM and BOM objects. The implementation of these objects is provided by the browser ~~ In IE... you can use vbscript to implement document... Of course there are other languages to implement ..

All is a unique attribute of IE. It seems like it is. I'm not sure ~~ It means to return the collection of all the DOM in the document...
Form. numeric is the numeric object under the form object ~ This may be the case.
<Form id = "form"> <input type = "text" id = "numeric"/> </form>

The recommended book is <JavaScript advanced programming> ~ Is the Basic book ~~

If you do not want to buy books ~~ You can refer to the following two manuals... JScript manuals (JScript Language for MS, refer to 99%) and DHTML manuals (also for MS .. For DOM )~

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.