'Add the variable to the given scope or current scope
If the scope is a
* variable or object: add as a variable to this scope.
* class: add as a member to this class.
* function: then this is a little more tricky:
* If it\'s class function, then add as a member for the class.
* If it\'s a function inside a variable/object, then add as a
variable to the variable/object.
* If it\'s just a function on it\'s own, turn the function into a
class and then add a member variable for the class.'

def addClassOrVariableMember(self, namelist, typeNames, scope=None, doc=None, assignAsCurrentScope=False, isLocal=False, varCtor=JSVariable):

    if (not scope):
        scope = self.currentScope
    log.debug('addClassOrVariableMember:    namelist:%r,    type:%r,    isLocal:%r,    scope    (%s):%s', namelist, typeNames, isLocal, scope.cixname, scope.name)
    memberName = namelist[(-1)]
    if ((len(namelist) > 2) and ('prototype' in namelist)):
        pIndex = namelist.index('prototype')
        scopeNames = namelist[:pIndex]
        log.debug('Adding    class    prototype.    class    name:    %r,    variable:    %r', scopeNames, memberName)
        scope = self._addClassPart(memberName, self.ADD_CLASS_MEMBER, scopeNames=scopeNames, args=None, doc=doc, path=self.path, varCtor=varCtor)
        v = scope
    elif (len(namelist) >= 2):
        scope = self._findOrCreateScope(namelist[:(-1)], attrlist=('variables', 'classes'), fromScope=scope)
        v = varCtor(memberName, scope, self.lineno, self.depth, vartype=typeNames, doc=doc, isLocal=isLocal, path=self.path)
        v = scope.addVariable(memberName, value=v)
        if assignAsCurrentScope:
            self.currentScope = v
    elif (scope.cixname in ('object', 'variable')):
        if isLocal:
            log.warn('addClassOrVariableMember:    %s:%d    Trying    to    add    %r    as    a    local    member    variable??', self.cile.name, self.lineno, namelist)
            return
        v = varCtor(memberName, scope, self.lineno, self.depth, vartype=typeNames, doc=doc, isLocal=isLocal, path=self.path)
        v = scope.addVariable(memberName, value=v)
        if assignAsCurrentScope:
            self.currentScope = v
    elif (isinstance(scope, JSClass) or scope.isAnonymous()):
        v = varCtor(memberName, scope, self.lineno, self.depth, vartype=typeNames, doc=doc, isLocal=isLocal, path=self.path)
        v = scope.addMemberVariable(memberName, value=v)
        if assignAsCurrentScope:
            self.currentScope = v
    elif isinstance(scope, JSFunction):
        parentScope = scope.parent
        if (not parentScope):
            log.debug('addClassOrVariableMember:    ignoring    assignment    %r    into    a    dummy    function', namelist)
            return None
        log.debug('ParentScope    is:    %s    (%s)', parentScope.name, parentScope.cixname)
        if isinstance(parentScope, JSClass):
            self.currentClass = parentScope
            log.debug('Assigning    to    parent    class:    %r:%r', parentScope.cixname, parentScope.name)
            v = varCtor(memberName, parentScope, self.lineno, self.depth, typeNames, doc=doc, isLocal=isLocal, path=self.path)
            v = parentScope.addMemberVariable(memberName, value=v)
            if assignAsCurrentScope:
                self.currentScope = v
        elif (parentScope and (parentScope.cixname in ('object', 'variable'))):
            log.debug('Assigning    to    parent    scope:    %r:%r', parentScope.cixname, parentScope.name)
            v = varCtor(memberName, parentScope, self.lineno, self.depth, vartype=typeNames, doc=doc, isLocal=isLocal, path=self.path)
            v = parentScope.addVariable(memberName, value=v)
            scope._parent_assigned_vars.append(v)
            if assignAsCurrentScope:
                self.currentScope = v
        else:
            func = scope
            funcName = func.name
            jsclass = self._locateScopeForName([funcName], attrlist=('classes',), scope=scope)
            if (not jsclass):
                log.debug('Creating    class    %r,    function    %r    now    ctor', funcName, funcName)
                jsclass = self._convertFunctionToClass(func)
            else:
                self._convertFunctionToClassContructor(func, jsclass)
            v = varCtor(memberName, jsclass, self.lineno, self.depth, typeNames, doc=doc, isLocal=isLocal, path=self.path)
            v = jsclass.addMemberVariable(memberName, value=v)
            if assignAsCurrentScope:
                self.currentScope = v
    elif isinstance(scope, JSFile):
        v = self.addVariable(namelist, typeNames, scope, doc, assignAsCurrentScope, isLocal, varCtor=varCtor)
    else:
        log.info('addClassOrVariableMember::    Invalid    scope    type.    Could    not    add    %r    to    scope:    %r    -    %r', namelist, scope.cixname, scope.name)
        v = None
    return v
