def __init__(self, func, prototype=None, extensible=True, source=None):
cand = fix_js_args(func)
has_scope = cand is func
func = cand
self.argcount = six.get_function_code(func).co_argcount - 2 - has_scope
self.code = func
self.source = source if source else '{ [python code] }'
self.func_name = func.__name__ if not func.__name__.startswith('PyJs_anonymous') else ''
self.extensible = extensible
self.prototype = prototype
self.own = {}
#set own property length to the number of arguments
self.define_own_property('length', {'value': Js(self.argcount), 'writable': False,
'enumerable': False, 'configurable': False})
if self.func_name:
self.define_own_property('name', {'value': Js(self.func_name), 'writable': False,
'enumerable': False, 'configurable': True})
# set own prototype
proto = Js({})
# constructor points to this function
proto.define_own_property('constructor',{'value': self, 'writable': True,
'enumerable': False, 'configurable': True})
self.define_own_property('prototype', {'value': proto, 'writable': True,
'enumerable': False, 'configurable': False})
评论列表
文章目录