The company's JS pen Test ~ You can the JS Foundation in prison!

Source: Internet
Author: User

The company's JS pen Test ~ You can the JS Foundation in prison. Hey heh code 1 var flag = true;
2 var flag2 = true;
3 if (flag = = True)
4 {
5 var i = 0;
6
7 J = 1;
8
9 if (Flag2 = = True)
10 {
One for (var m = 0 M < m + +)
12 {
13
14}
15}
16}
17
alert (i);
Alert (j);
Alert (m);


Output 0, 1, 10

var x = 1;

function Scopetest () {
alert (x);
}

Scopetest (); Output 1


Output 1

var x = 1;

function Scopetest () {
alert (x);
var x = ' Hello World ';
alert (x);
}

Scopetest ();


Output underfined, Hello World

var name = ' Laruence ';
function Echo ()
{
alert (name);
}
function env ()
{
var name = ' Eve ';
Echo ();
}

Env ();


Output laruence

function test (XXX) {
alert (XXX);
var xxx = 123;
function xxx () {
}
alert (XXX);
}
Test (444);


Output function xxx () {},123

Code function Jsclass () {
this. M_text = ' division element ';
this. m_element = document.createelement (' DIV ');
this. m_element.innerhtml = this. M_text;

this. M_element.attachevent (' onclick ', this. ToString);
}

JSClass.prototype.Render = function () {
Document.body.appendChild (this. m_element);
}

JSClass.prototype.ToString = function () {
Alert (this. m_text);
};

var JC = new Jsclass ();
Jc. Render (); Add Render div element
Jc.  ToString (); Output Division Element

Click the div element that is added division the underfined, why.


Click the div element that is added division the underfined, why.

The This keyword in the EventHandler () method indicates that the object is the window object for IE.
This is because EventHandler is just an ordinary function, for attachevent after
The script engine has no relationship to its invocation and the Div object itself. And you can look at the caller properties of EventHandler,
It is equal to null. If we want to get a Div object reference in this method, we should use: This.event.srcElement.

  Code             var  obj  =  {
            i:  "Test",
             m:  function ()  {
                 alert (this. i); //point to Obj object   instance, Output value test 
                  function  b ()  {
                     alert (

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.