New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows for first new Response argument to be options #577
Conversation
# Conflicts: # fetch.js # test/test.js
var getClassOf = Function.prototype.call.bind(Object.prototype.toString) | ||
|
||
var isClassOf = function (instance, className) { | ||
return getClassOf(instance).split(' ')[1] === className + ']' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get away with a simpler check?
function isPlainObject(obj) {
return obj != null && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]'
}
var options | ||
|
||
// if the first argument is options and not body | ||
if (isClassOf(arguments[0], 'Object')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like
function Response(bodyInit, options) {
if (arguments.length === 1 && isPlainObject(bodyInit)) {
options = bodyInit
bodyInit = null
}
// ...
}
@@ -603,6 +603,12 @@ suite('Response', function() { | |||
|
|||
assert.equal(r.headers.get('content-type'), 'text/plain') | |||
}) | |||
|
|||
test('accepts options as first parameter', function () { | |||
var r = new Response({ status: 200 }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use a non-default status such as 204 to verify that the status was successfully assigned.
Fixes #576