当前位置:网站首页>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
*/
边栏推荐
- DLL load failed: the page file is too small to complete the operation
- Custom types in C language
- Wechat sports field reservation of the finished works of the applet graduation project (5) assignment
- [pyGame practice] nostalgic classic - do you remember the name of this chess game for children? (must collect)
- Pycharm writes SQLite statements without code prompts
- Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
- Unity refers to a variable in another class (its own instance)
- Study notes of filebeat
- Master jedispoolconfig parameter configuration and learn tuning skills
- It's still a synchronization problem
猜你喜欢

On Calc optimization of calcite

JS foundation -- hijacking of this keyword

Nuscenes data set summary

Do you know about real-time 3D rendering? Real time rendering software and application scenarios are coming

JS foundation -- data

What are you working for? Don't give up is our only choice, come on, everyone

Vulntarget vulnerability shooting range -vulntarget-b

Redis unauthorized access vulnerability recurrence (www.hetianlab.com)

BMW I3 based on clar architecture is not a simple "oil to electricity" product

Application method and practical case of sqlmap of penetration test SQL injection
随机推荐
Js a simple way to store several objects in an array
[system design] distributed key value database
6. Object storage
MySQL common function summary, very practical, often encountered in interviews
Resolved (the latest version of selenium reported an error) attributeerror: module 'selenium webdriver‘ has no attribute ‘PhantomJS‘
Operator explanation - C language
ICO objects in classification
Using the artifact typora+picgo, Youdao cloud can automatically upload pictures in markdown without members
Is it necessary to increase the number of milliseconds and save several KB of memory in the program?
Cloudrev deploy your own public cloud disk (pagoda installation method)
6.0 cancellation of member registration verification code
My creation anniversary (3rd Anniversary)
Sequence diagram of UML diagram series
# CF #808 Div.2(A - C)
Arduino + si5351 square wave generator
Large number processing -- use case
Nuscenes data set summary
Get to know string thoroughly
Tp5.1 include include files (reference public files)
Physical experiment simulation