What is the purpose of these internal functions?

Javascript compiles this code without :

function test() {
    property: true;
    alert('testing');
}
test(); // Shows message 'testing'
alert(test.property); // Shows 'undefined'

Is the content of the property accessible in any way?

If not, what is the purpose of adopting this code?

+3
source share
2 answers

propertyhere is not a property. This shortcut is something you can use with breakor continue. You can reformat the code that you have:

function test() {
    property: 
        true;
        alert('testing');
}

You don’t actually refer to the label, and what happens after it (true) is just a no-op operation, so nothing happens when it is executed. The function only contains a warning statement.


, . :

var test = {
    property: true;
};

. , .

+3
 test = function() {
    this.property = true;
    alert('testing');
}
var test = new test(); // Shows message 'testing'
alert(test.property); // Shows 'true'

'this' , .

this.property = true;

, :

var test = new test();
0

Source: https://habr.com/ru/post/1759612/


All Articles