kikito / middleclass

Object-orientation for Lua
https://github.com/kikito/middleclass
MIT License
1.77k stars 190 forks source link

i think line 118 is not right. #39

Closed woshihuo12 closed 8 years ago

woshihuo12 commented 8 years ago

Line 118:typeof (aClass.isSubclassof)=="function. Should be self.class .issubclassof

TangentFoxy commented 8 years ago

Are you saying aClass specifically should be class? Your writing is not very clear.

woshihuo12 commented 8 years ago
DefaultMixin = {
  __tostring   = function(self) return "instance of " .. tostring(self.class) end,

  initialize   = function(self, ...) end,

  isInstanceOf = function(self, aClass)
    return type(self)       == 'table' and
           type(self.class) == 'table' and
           type(aClass)     == 'table' and
           ( aClass == self.class or
             type(aClass.isSubclassOf) == 'function' and    -- this this this issue issue issue
             self.class:isSubclassOf(aClass) )
  end,

type(self.class.isSubclassOf)=='function' and

Look the comment. I think above should be right!

TangentFoxy commented 8 years ago

You're still not being very clear. Also, could you please put backticks around code blocks to make it legible?

Ex:

screenshot_2016-06-27_10-41-13

Turns into:

code
woshihuo12 commented 8 years ago

i make a change..

kikito commented 8 years ago

Hi there,

Both instanceOf and subclassOf have evolved from an earlier version of middleclass where they not always were "attached" to instances of objects. As a result, they had to do a lot of extra checks (because you could call them with parameters of any type, like instanceOf(1, "hello") -> and that should return false without failing. As a result, they had to do lots of extra checks like "is this a table?", "is this a class?" etc.

In the new versions of middleclass this is no longer the case. instanceOf is always called from an instance, and subclassOf is always called from a class. This probably means that some of those extra checks might be no longer needed. Line 118 seems to fall into that category.

Let me think about this for a some more days (I am a bit busy right now in real life) and I will get back to you on that.

Thank you for creating an issue in any case!

kikito commented 8 years ago

Hi again,

After meditating about this for a while I have decided to simplify isInstanceOf and isSubclassOf - they now work only on classes and instances, and as such they need far less "checks". One of the checks removed is the one which provoked this issue.

I have also released middleclass 4.1.0 with the change.

Regards!