I kept getting the feeling I was misunderstanding what you are trying to do. Maybe you're looking for a way to run something only the first time a script is used hence the Constructor analogy
This example is a combination of the previous one with the concept of a "constructor" (run once). If you tried to use __newindex you would only get errors trying to do anything with the frame. (I hope this covers it because I'm out of ideas as to what you're looking for

)
Lua Code:
local mt = {
AppendScript = function(self, handler, method)
local func = self:GetScript(handler)
self:SetScript(handler, function(self, ...)
if func then -- SetScript() if used
func(self, ...)
end
method(self, ...) -- then appended script
end)
end,
ConstructScript = function(self, handler, method)
local func = self:GetScript(handler)
self:SetScript(handler, function(self, ...)
if method then -- Constuctor method runs first
method(self, ...)
method = nil
end
if func then -- then SetScript() if used.
func(self, ...)
end
end)
end,
}
local frame = CreateFrame("BUTTON", "MyHookedFrame", UIParent, "BackdropTemplate")
setmetatable(frame, { __index = setmetatable(mt, getmetatable(frame)) })
frame:SetSize(200, 40)
frame:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8", tile = true, tileSize = 8 })
frame:SetBackdropColor(0, 0, 0)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
local count = 0
frame:SetScript("OnEnter", function(self) -- Set/HookScript required to allow other scripts to be appended
count = count + 1
print(count, "|cff00ff00First Frame OnEnter Script|r")
end)
local function Construct(self, ...)
print(count, self:GetName(), "|cffff0000Only going to show you this once!!!|r", ...)
end
frame:ConstructScript("OnEnter", Construct)
local function AppendScriptOne(self, ...)
print(count, self:GetName(), "|cff0000ffFirst Appended On Enter!!!|r", ...)
end
frame:AppendScript("OnEnter", AppendScriptOne)
local function AppendScriptTwo(self, ...)
print(count, self:GetName(), "|Cffffff00Second Appended On Enter!!!|r", ...)
end
frame:AppendScript("OnEnter", AppendScriptTwo)
local frame2 = CreateFrame("BUTTON", "MyHookedFrame2", UIParent, "BackdropTemplate")
setmetatable(frame2, { __index = setmetatable(mt, getmetatable(frame2)) })
frame2:SetSize(200, 40)
frame2:SetBackdrop({ bgFile = "Interface\\BUTTONS\\WHITE8X8", tile = true, tileSize = 8 })
frame2:SetBackdropColor(0, 0, 0)
frame2:SetPoint("TOP", frame, "BOTTOM", 0, -10)
-- Optional SetScript not used here (unless you want to uncomment it.)
--frame2:SetScript("OnEnter", function(self) -- Set/HookScript required to allow other scripts to be appended
-- count = count + 10
-- print(count, "|cff00ff00Second Frame OnEnter Script|r")
--end)
frame2:ConstructScript("OnEnter", Construct)
frame2:AppendScript("OnEnter", AppendScriptOne)
frame2:AppendScript("OnEnter", AppendScriptTwo)
Overly complicated!