当前位置:网站首页>JS written test question -- prototype, new, this comprehensive question
JS written test question -- prototype, new, this comprehensive question
2022-07-25 02:49:00 【H5_ ljy】
function fn() {
a = function() {
console.log("111111")
}
return this
}
fn.a = function() {console.log("222222")}
fn.prototype.a = function() {console.log("333333")}
var a = function() {console.log("444444")}
function a() {console.log('555555')}
fn.a()
a()
fn().a()
a()
new fn.a()
new fn().a()
new new fn().a()
// analysis
/*
Implicit promotion :
var a;
function fn() {
a = function() {
console.log("111111")
}
return this
};
function a() {console.log('555555')};
fn.a = function() {console.log("222222")};
fn.prototype.a = function() {console.log("333333")}
a = function() {console.log("444444")}
fn.a() // Print 222222
a() // Print 444444
fn().a() // function fn function Change global variables var a=function() {console.log("111111")}
// return this=>window, then window.a()=> Print 111111
a() // Print 111111
// priority =>() > Some grammar |new Banded ginseng > new No arguments | Function run
//new Three steps :1. Create an empty object ,2. Run constructor internal this Point to this object ,3. The result depends on the return value => If it is reference data, return it , Otherwise, it is the object after running
new fn.a() // new (fn.a)() => Print 222222
new fn().a() // (new fn()).a() => Inside this by =>new Constructed empty object , Because there is no a Method , Then find the prototype , Print 333333
new new fn().a() //new (new fn()).a() => Similar to that , Print 333333
*/
边栏推荐
- Mp4 package analysis
- Permanently mount the image steps
- Wechat sports field reservation of the finished works of the applet graduation project (7) mid-term inspection report
- Rolling division, Young's matrix and three-step flip
- Object.defineproperty use
- Consul cluster deployment
- "Introduction to interface testing" punch in to learn day09: Micro service interface: how to use mock to solve chaotic call relationships
- "Introduction to interface testing" punch in to learn day05: how can a testing framework support restful interfaces?
- Beginners must see the markdown User Guide
- Large number processing -- use case
猜你喜欢

Object.defineproperty use

DLL load failed: the page file is too small to complete the operation

Domestic edge computing organization and product research

TS uses a third-party library, and there is no type declaration file error handling

English grammar_ Reflexive pronoun
It's still a synchronization problem

Sword finger offer 11. rotate the minimum number of the array

Solution to the occupation of project startup port

Nuscenes data set summary

Pagoda workman WSS reverse proxy socket legal domain name applet chat remove port
随机推荐
Visualization of correlation coefficient matrix
R language one page and many pictures
Classic network learning RESNET code implementation
Ten year structure and five-year Life-03 trouble as a technical team leader
Three ways to solve your performance management problems
Details of C language compilation preprocessing and comparison of macros and functions
# CF #808 Div.2(A - C)
What are you working for? Don't give up is our only choice, come on, everyone
Nuscenes data set summary
[TinyML]EfficientFormer:Vision Transformers at MobileNet Speed
Details of happens before rules
It7259q-13, it7259ex-24 feature wearable devices
Map set learning
HAC cluster is modified to stand-alone
ICO objects in classification
Request and response
Wechat sports field reservation of the finished works of the applet graduation project (5) assignment
Keepalivetime=0 description of ThreadPoolExecutor
The latest interview questions and analysis of software testing in 2022
Simulate the implementation of StrCmp function