[webkit-dev] JSObjectCallAsFunctionCallback question
browserwk at gmail.com
Fri May 15 00:24:27 PDT 2009
I think i know you mean.
To get the method name ["getValue"] via attach a private data to function
object which create by JSObjectMake().
Yes, it's a better way, but not for me.
In my program, we have many Object and it's method and now all in staticFunc
On Fri, May 15, 2009 at 11:57 AM, Zhe Su <james.su at gmail.com> wrote:
> If you create a JSObject with JSObjectMake() function, you can have a
> private data associated to the newly created JSObject. You can store
> anything you want in the private data. So following approach might be
> feasible for you:
> 1. define a special JSClass for your function, which has finalize and
> callAsFunction set. In finalize() method, you need destroy the private data
> associated to the JSObject, if necessary. callAsFunction points to your
> 2. create the getValue function object by calling JSObjectMake() with the
> function name "getValue" as private data.
> 3. attach the function object to myObject with name "getValue". It might be
> done in myObject class's initialize() method.
> 4. in getValue_cb function you can retrieve the private data (which
> contains the name) by calling JSObjectGetPrivate(function).
> The only drawback of this approach: you can't declare the function
> statically in staticFunctions.
> James Su
> On Fri, May 15, 2009 at 10:53 AM, Xiong <browserwk at gmail.com> wrote:
>> Thanks Darin.
>> For the first problem, as you said, all the functions are objects, and
>> also have **properties**.
>> So,can we add a member for the "function object" to store the method
>> name[here is "getValues"] in theoretical ?
>> And this also like the "JSObjectRef object" variable in the callback
>> prototype,we can get the class name like this:
>> On Fri, May 15, 2009 at 10:29 AM, Darin Adler <darin at apple.com> wrote:
>>> On May 14, 2009, at 7:03 PM, Xiong wrote:
>>> 1 what is the purpose of the "JSObjectRef function" variable? In my
>>>> case, we never use.
>>> are objects. Like other objects they can have properties. This argument is
>>> passed to your C implementation so that it can get access to properties of
>>> the function object if it has some reason to. In many cases there is no need
>>> to do this.
>>> 2 In this function, i want to get the propertyName of the method, in
>>>> this case, we need "getValues", can be implemented ?
>>> No, there's no way to do that, for a good architectural reason.
>>> create an object with a prototype that has functions stored in its
>>> taking that function and storing it somewhere else, in a property with
>>> another name. When the function is called, it’s just an object, and there’s
>>> no way to go back in time and find out where that object came from.
>>> Consider the similar situation of a data property. When you get the
>>> length of an array, it's a number 1, not a number 1 that knows it came from
>>> a property named "length".
>>> -- Darin
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev