[removed] global scope

前端 未结 4 645
一个人的身影
一个人的身影 2021-02-03 12:15

Nowdays, i create a .js file with a lot of functions and then I link it to my html pages. That\'s working but I want to know what\'s the best way (good practices) to insert js i

4条回答
  •  走了就别回头了
    2021-02-03 13:01

    It's perhaps not the BEST way, but a lot of PHP systems (I'm looking at you, Drupal) take the name of their particular plugin and prepend it to all their function names. You could do something similar, adding the name of your capability to your function names - "mything_do_action()"

    Alternately, you could take a more "OO" approach, and create an object that encapsulates your capability, and add all your functions as member functions on IT. That way, there's only one thing in global scope to worry about.

提交回复
热议问题