View Single Post
03-29-20, 07:48 AM   #1
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
how is better to write ...

Hi all,

having a lot of times in this period I am here polishing and refreshing my addons code ...

A couple of questions:

1) having code like this:

Lua Code:
  1. local ldb = LibStub:GetLibrary("LibDataBroker-1.1")
  2. local dataobj = ldb:NewDataObject("gmVideoSwitch", {
  3.     type = "data source",
  4.     icon = "Interface\\Addons\\"..ADDON.."\\bluewin.tga",
  5.     text = "-"
  6. })

Lua Code:
  1. function dataobj.OnEnter(self)
  2.     -- code here
  3. end

or

Lua Code:
  1. dataobj.OnEnter = function(self)
  2.     -- code is here
  3. end

The above statement are equal I suppose, which is better to be written ?

And the second question.

Being defined as:

Lua Code:
  1. local dataobj

all its functions are local too automagically or it is better to defined them local too ?

Thanks.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote