[英]Explanation of Weird JavaScript Assignment Syntax
I was reading an article explaining function prototyping and inheritance in JavaScript when I came across these lines of code I can't wrap my head around 当我遇到这些代码行时,我读的一篇文章解释了JavaScript中的函数原型设计和继承,我对此无所适从
a = {}
(function(){}())
What exactly do these lines do? 这些行到底是做什么的?
a = {} // Be 'a' an empty object (But why ?)
function(){ // Declare a function that says Hello when it's called
alert("Hello");
}
function(){ // Declare a function that says Hello and execute it immediately with ()
alert("Hello");
}()
function(){}() // Declare a function that...does nothing, and execute it immediately with ()... But apparently you can't, that's a syntax error (Thanks @pointy)
(function(){}()) // Makes it work (no syntax error)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.