-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Open
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal
Milestone
Description
Proposal Details
In JS I can do this:
function hello(options) {
if ("name" in options) {
if (options.name === undefined) { // could be "== null" to handle null & undefined
console.log(`You've opted to not provide your name`)
} else if (typeof options.name === "string") {
console.log(`Hello ${options.name}!`)
} else {
throw new TypeError("name is not a string")
}
} else {
console.log(`Name field is empty. Would you like to set it now?`)
// blah blah
}
}This example illustrates the potential difference in semantics between a property being not present on an object and being undefined on an object.
You cannot currently detect the presence or absence of a property using syscall/js without resorting to calling Reflect.has(object, propertyName) via js.Global().Get("Reflect")...
I propose adding a Value.Has or similar method to expose the JS in operator similar to how instanceof is exposed.
Metadata
Metadata
Assignees
Labels
LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal