Re: [XHR2] Blobs, names and FormData

On 8/24/11 11:36 PM, Jonas Sicking wrote:
> On Wed, Aug 24, 2011 at 12:57 PM, Charles Pritchard<chuck@jumis.com>  wrote:
>    
>>>> Prpoposed:
>>>>
>>>> FormData output with the x-www-form-urlencoded mime type:
>>>> formData.toUrlEncodedBlob(xhr.send)
>>>>
>>>> If going down the blob path, these two would have the same end-result:
>>>> formData.toMultipartBlob(xhr.send)
>>>> xhr.send(formData);
>>>>          
>>> What kind of API-style is this?
>>>
>>>        
>> [Supplemental] FormData
>> void toMultipartBlob(in callback)
>> void toUrlEncodedBlob(in callback)
>>
>> The first would create a multipart mime message, in a blob, and run the
>> callback with the blob as the first argument,
>> the second would create a urlencoded message, in a blob, and also run the
>> callback.
>> They'd set the appropriate content type on generated blob.
>>      
> The syntax you've written above wouldn't work in JS. You're only
> passing in a reference to the send function, not a reference to the
> XHR object on which to call .send on. So
>
> formData.toMultipartBlob(xhr.send)
>
> is equivalent to
>
> formData.toMultipartBlob(XMLHttpRequest.prototype.send)
>
> So in this case you'd have to pass in two argument, the function and
> the 'this' object. Or require people to use .bind.
>
> In general I'm not a fan of this syntax.
>
> / Jonas
>
>    
You're right on that end. Sorry for the confusion.

xhr.send(formData) would be the same as:
formData.toMultipartBlob(function(blob) { xhr.send(blob); });

I didn't mean to propose fancy scope items.


-Charles

Received on Thursday, 25 August 2011 06:57:06 UTC