Python Learning Day 54th: scope objects and how to use them

Source: Internet
Author: User

1. JS Scope 1.1 Global scope and local scope
    • The global scope is declared outside the function
    • Inside a function is a local scope
    • Global variables can be modified and used directly within a function
    • variables, which var are declared using, are not var using variables. If you use within a function var to declare a variable, a global variable with the same name will be overwritten within the function
1.2 Variable Promotion
    • Going to use a variable before the variable declaration will get undefined, not an error
    • function, if you declare a local variable with the same name as the global variable, use the change amount before the declaration to get the undefined (the variable is already local)
1.3 Scope Chain
    • When a variable is used in a scope, it is looked up from this scope, and if there is no parent scope, then there is no parent scope of the parent scope until the global scope. constitutes a chain of scopes
1.4 Closures
    • It is usually necessary to return a function in a function
    • Objective to use the data of a local scope for the scope of the outer area.
1.5 ES6 new block-shaped scope
    • letKeywords can also declare variables, same var as
    • However let , the variable declared by the keyword will produce a block scope in the structure statement
    • ES6 recommends using let instead of Var
2. JS Object 2.1 Constructors and objects
构造就是类function User([参数]) { this.属性 = 值; this.属性 = 值; this.方法 = function(){ }}#实例一个对象new 构造函数();如果构造函数没有参数 可以 不加()
2.2 JS prototype and prototype chain prototype
    • Each object has a prototype (the prototype is still an object)
    • Objects can inherit properties and methods of a prototype
    • __proto__All objects have this property, which points to the prototype of the object
Prototype chain
    • Prototypes also have prototypes as objects
    • Prototypes of prototypes form the prototype chain.
    • When using a property in an object, first look it up from the object, if not, from the prototype, if not, the prototype will continue to look up until the top level (the top-level prototype object is a type (class) (constructor) object)
2.3 The invocation of the JS object property
.  点obj.nameobj.age[]  中括号obj[‘name‘]obj[‘age‘]任意的对象都可以在对象实例化完成后,添加属性和方法
2.4 Object Constructor
js內建的构造方法叫Objectvar obj = new Object()json方式定义对象var obj = {属性:值,属性:值}new Object()的简写
Practical tips 3.1 Getting elements from a page
document.getElementById()根据ID的值获取元素对象document.getElementsByTagName()根据标签名取元素对象document.getElementsByClassName()根据class的值取元素对象document.getElementsByName()根据name属性的值获取元素对象document.querySelector(css选择器)返回满足条件的第一个元素对象document.querySelectorAll(css选择器)返回所有满足条件元素组成的类数组对象
3.2 Binding an event to an element
先获取元素ele.onclick = function(){    }获取元素的类数组对象, 遍历,挨个给每个元素绑定事件
3.3 Modifying the CSS style of an element
ele.style.css属性名ele.style.backgroundele.style.borderele.style.backgroundColorele.style[‘background-color‘]
3.4 Setting the class value of an element
ele.className可以赋值,也可以获取ele.classList.add(‘值‘)添加一个class值ele.classList.remove(‘值‘)删除一个class值ele.classList.toggle(‘值‘)自动切换一个class值(有就删除,没有就添加)
3.5 Events
onclick         单机ondblclick      双击oncoutextmenu   右击onmouseover/onmouseenter鼠标悬浮在元素上onmouseout/onmouseleave鼠标离开元素onmousemove 鼠标在上面移动onmousedown 鼠标的按键按下onmouseup 鼠标的按键抬起
3.6 JS timed single time timing
setTimeout(fn,delay)clearTimeout() 清除定时
Multiple timing
setInterval(fn,dealy)clearInterval() 清除定时

Python Learning Day 54th: scope objects and how to use them

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.