All those snippets allow to reference the node itself.
Of course, most times, you don't need to do this at all. Simply writing the property name position without any prefix accomplishes the same:
extendsNode2Dfunc_ready()->void:
position =Vector2(200,200)
So you rarely need to use self.
When to use `self`?
There are two instances where self is mandatory:
when shadowing variables
when tweening the current node
when accessing dynamic properties
Shadowing
"shadowing" is when a new variable named like the class variable prevents accessing it. Let's say you have a function that sets the position, like so:
funcchange_position(position:Vector2)->void:# ...
How would you be able, in the function body, to differentiate between the propertyposition and the parameterposition?
funcchange_position(position:Vector2)->void:
position = position
Writing position would only reassign the parameter to itself, because Godot will only use the last occurence of a name. To fix this, you'd use self:
funcchange_position(position:Vector2)->void:
self.position = position
Of course, it'd be better in this case to change the parameter name. You can read more about this in the scope article.
Reference for other functions
The second, and arguably more essential reason to use self is when you need to reference the node, mostly for tweens.
Let's say you want to tween the current node; the Tween.tween_property() method needs a node to act on. When trying to animate a different node, you might write:
var tween :=create_tween()
tween.tween_property($Sprite,"position",Vector2(100,200),1.0)
But if you need to tween the current object itself, you'll need to use self:
var tween :=create_tween()
tween.tween_property(self,"position",Vector2(100,200),1.0)
You might also imagine needing to pass the reference to other nodes.
For example, owner is a property set by the editor automatically when creating nodes, but it's empty for nodes you create programmatically. If you wanted to set it, you may do:
Sometimes, you may want to call a property dynamically. In the example below, we want to run take_damage_[element_name](), where element_name is fire, water, or banana: