I am reading the jQuery plug-in written in CoffeeScript, but I do not understand the description of @.What does it stand for?
self=@
Also, what does @ mean in Javascript and jQuery?
Even if I look for it in the book, there is no description of @.
Description of the home site
All together now:
In the comparison table section of ,
CoffeeScript JavaScript
@, this this
It appears to represent this
in JavaScript (you can think of it as the same).
As a shortcut for this.property, you can use@property.
There is an explanation that
this.property
seems to be a shortcut to write like @property
.
JavaScript changes the meaning of this in the same context depending on where it is called.
In CoffeeScript, you can use @ in a cool way other than reducing the number of this types.
For example, if you want to do something like this
hoge=function(){
var foo;
This.piko=123
foo=function(){
return this.piko
}
}
The piko property
declared above cannot be used in the foo function
.
If you really want to use it, you will need a little trick.
hoge=function(){
varself = this;
var foo;
This.piko=123;
foo=function(){
return self.piko
}
};
This is what happens when you write in CoffeeScript to achieve this.
hoge=->
@piko=123
foo==>
@piko
If you want to bring this into the unknown function,
By simply defining a function in =>
, you can generate a second roundabout JavaScript.
(I think a similar specification was adopted in ES6)
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
626 Uncaught (inpromise) Error on Electron: An object could not be cloned
618 GDB gets version error when attempting to debug with the Presense SDK (IDE)
© 2024 OneMinuteCode. All rights reserved.