Skip to content

Comments

Function - Rename properties and methods to include prototype#18200

Merged
Josh-Cena merged 50 commits intomainfrom
unknown repository
Jul 15, 2022
Merged

Function - Rename properties and methods to include prototype#18200
Josh-Cena merged 50 commits intomainfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Jul 11, 2022

Summary

Renames properties such as Function.name to Function.prototype.name.

Motivation

Consistency.

Supporting details

N/A.

Related issues

Fixes #18188.

Metadata

  • Adds a new document
  • Rewrites (or significantly expands) a document
  • Fixes a typo, bug, or other error

@github-actions github-actions bot added the Content:JS JavaScript docs label Jul 11, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 11, 2022

Preview URLs

Flaws

Note! 9 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
Title: Function
on GitHub
Flaw count: 1

  • bad_bcd_links:
    • no explanation!

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller
Title: Function.prototype.caller
on GitHub
Flaw count: 1

  • macros:
    • /en-US/docs/Web/JavaScript/Reference/Functions/arguments/caller does not exist

External URLs

URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
Title: Function
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/arguments
Title: Function.prototype.arguments
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
Title: Function.prototype.name
on GitHub


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply
Title: Function.prototype.apply()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/length
Title: Function.prototype.length
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/displayName
Title: Function.prototype.displayName
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/toString
Title: Function.prototype.toString()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
Title: Function.prototype.call()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
Title: Function.prototype.bind()
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function
Title: Function() constructor
on GitHub

No new external URLs


URL: /en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller
Title: Function.prototype.caller
on GitHub

No new external URLs

(this comment was updated 2022-07-15 10:26:45.239582)

@ghost ghost marked this pull request as ready for review July 15, 2022 03:33
@ghost ghost self-requested a review as a code owner July 15, 2022 03:33
@ghost ghost requested review from Josh-Cena and removed request for a team July 15, 2022 03:33
Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks much better to me; mostly minor suggestions

`apply` is very similar to `call()`, except for the type of arguments it supports. You use an arguments array instead of a list of arguments (parameters). With `apply`, you can also use an array literal, for example, `func.apply(this, ['eat', 'bananas'])`, or an {{jsxref("Array")}} object, for example, `func.apply(this, new Array('eat', 'bananas'))`.

You can also use {{jsxref("Functions/arguments", "arguments")}} for the `argsArray` parameter. {{jsxref("Functions/arguments", "arguments")}} is a local variable of a function. It can be used for all unspecified arguments of the called object. Thus, you do not have to know the arguments of the called object when you use the `apply` method. You can use `arguments` to pass all the arguments to the called object. The called object is then responsible for handling the arguments.
You can also use {{jsxref("Functions/arguments", "arguments")}} for the `argsArray` parameter. `arguments` is a local variable of a function. It can be used for all unspecified arguments of the called object. Thus, you do not have to know the arguments of the called object when you use the `apply` method. You can use `arguments` to pass all the arguments to the called object. The called object is then responsible for handling the arguments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I don't grasp this paragraph. Is it talking about something like this?

function foo() {
  bar.apply(null, arguments);
}

Maybe we can merge it with the paragraph below about array-like objects, saying something like "arguments is array-like so you can pipe it through—this is equivalent to using function foo(...args) { bar(...args) }?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems to be redundant in that it describes being array-like, without saying "array-like."

@ghost
Copy link
Author

ghost commented Jul 15, 2022

@Josh-Cena I'm still reviewing your feedback, but just to confirm, it seems like you're interested in broadening this to a light rewrite/update of Function/*?

@Josh-Cena
Copy link
Member

Josh-Cena commented Jul 15, 2022

No—I'm just dropping random thoughts as I go through the diff. I'm not particularly interested in re-writing outside the diff.

@ghost
Copy link
Author

ghost commented Jul 15, 2022

Understood, it's just that there are definitely plenty of similar issues outside of the diff.

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done a few changes and at least the diffed regions look good enough to me.

I'm going to go ahead and merge this. Any extra modernization attempts can go into follow-up PRs.

@Josh-Cena Josh-Cena merged commit 10e9198 into mdn:main Jul 15, 2022
@ghost ghost deleted the function branch July 15, 2022 21:43
bind(thisArg, arg1)
bind(thisArg, arg1, arg2)
bind(thisArg, arg1, ... , argN)
bind(thisArg, arg1, …, argN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phosra why did you change these?
As per the MDN Web Docs guidelines, https://developer.mozilla.org/en-US/docs/MDN/Structures/Syntax_sections#syntax_for_arbitrary_number_of_parameters , it's correct. Including the ellipsis.

We updated all the pages as per these guidelines couple of month ago.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were done by @Josh-Cena.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh @OnkarRuikar I wasn't aware of that convention ^^ If you want to send a quick fix I will gladly review it.

call(thisArg, arg1)
call(thisArg, arg1, arg2)
call(thisArg, arg1, ... , argN)
call(thisArg, arg1, …, argN)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call(thisArg, arg1, /* … ,*/ argN)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properties of Function vs. Function.prototype

2 participants