2

I am trying to create regions at my javascript code written in HTML <script>...</script> tag to categorize it by collapsing. I tried following code that I found here but nothing happened. Is there any method to do it in HTML <script> tag?

Here is my code:

<script>

//#region DataTable Functions
function initRoomTable(){
    $('#room-table').DataTable({
    ...
    })
}
function initParticipantTable(){
    $('#participant-table').DataTable({
    ...
    })
}
//#endregion DataTable Functions

//#region Init Page
$(document).ready(function () {
    initRoomTable();
    initParticipantTable();
})
//#endregion Init Page

</script>
KaraKaplanKhan
  • 579
  • 1
  • 9
  • 25

2 Answers2

1

This depends on where you view your code, some IDEs might recognize those functions and collapse them by default or offer a + or similar sign to collapse when you click but AFAIK there is no element inside JS to offer code collapsing.

What you need is some kind of instruction to your IDE or browser how to display code in dev tools or have smart enough IDE (or some extension to the browser?) to do the same. That is certainly not the part of the JS itself.

That is the reason why author claims that code is presented with collapsible functions and you are not seeing it. It might be due to where you view your code compared to where the author does OR it can even be a setting within IDE.

DanteTheSmith
  • 2,193
  • 1
  • 9
  • 27
1

Regions in JS are only recognized by certain code editors.

If you are viewing your code in Notepad or any other simple editor, chances are that they wont be picked up on.

Most editors have extensions for stuff like that, others have it implemented by default:

ThatBrianDude
  • 2,312
  • 2
  • 10
  • 40