Title: JavaScript function overloading (Example)
Open Graph Title: JavaScript function overloading (Example)
X Title: JavaScript function overloading (Example)
Description: A protip by steveniseki about functions and javascript.
Open Graph Description: A protip by steveniseki about functions and javascript.
X Description: A protip by steveniseki about functions and javascript.
Keywords:
Mail addresses
support@coderwall.com
Opengraph URL: https://www.coderwall.com/p/bdadoa/javascript-function-overloading
X: @coderwall
Domain: coderwall.com
IPv4 address: 66.71.205.0
{
"@context": "http://schema.org",
"@type": "Article",
"@id": "javascript-function-overloading",
"author": {
"@type": "Person",
"name": "Steven Iseki"
},
"dateModified": "2019-08-26 22:02:52 UTC",
"datePublished": "2019-08-26 22:02:52 UTC",
"headline": "JavaScript function overloading (Example)",
"url": "/p/bdadoa/javascript-function-overloading",
"commentCount": 1,
"keywords": "functions, javascript",
"articleBody": "This is a simple example of function overloading in JavaScript using closures to overload a Users.find() method, we can overload the method with either a name or a first name, last name.\r\n\r\nThanks to Steve Jansen http://steve-jansen.github.io/ for this example\r\n\r\n (function(){\r\n function findAll() {\r\n // Find all users...\r\n }\r\n \r\n function findByFullName(name) {\r\n // Find a user by name\r\n }\r\n \r\n function findBySurname(first, last) {\r\n // Find a user by first and last name\r\n }\r\n \r\n Users.prototype.find = function find() {\r\n if (arguments.length === 0)\r\n return findAll.apply(this);\r\n \r\n if (arguments.length === 1 and typeof(arguments[1]) === 'string')\r\n return findByFullName.apply(this, arguments);\r\n \r\n // by default, search using first and last name\r\n return findBySurname.apply(this, arguments);\r\n }\r\n })();",
"description": "A protip by steveniseki about functions and javascript.",
"publisher": {
"@type": "Organization",
"name": "Coderwall",
"logo": {
"@type": "ImageObject",
"url": "/logo.png"
},
"url": "https://www.coderwall.com/"
},
"image": "/logo.png"
}
{
"@context": "http://schema.org",
"@type": "Comment",
"datePublished": "2018-06-21 08:34:20 UTC",
"text": "in find() correctly should be: \r\n if (arguments.length === 1 \u0026\u0026 typeof(arguments[0]) === 'string')",
"upvoteCount": 0,
"author": {
"@type": "Person",
"name": "zemiak"
},
"about": {
"@type": "Article",
"@id": "javascript-function-overloading"
}
}
| og:site_name | Coderwall |
| og:type | website |
| og:image | https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/98069/stevenm.jpg |
| twitter:url | https://www.coderwall.com/p/bdadoa/javascript-function-overloading |
| twitter:site_name | Coderwall |
| twitter:card | summary |
| twitter:creator:id | 407006088 |
| twitter:image | https://coderwall-assets-0.s3.amazonaws.com/uploads/user/avatar/98069/stevenm.jpg |
| author | https://www.coderwall.com/steveniseki |
| csrf-param | authenticity_token |
| csrf-token | tBF41Gu6PlKapxjUSA8GhlQZj9Wj-nvY4HXwtZOubc7L0wkt7TyiDXTuD3Um4V8eRUggiR6czx6KE5NU6gUgdA |
Links:
| Server | envoy |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
| Last-Modified | Mon, 26 Aug 2019 22:02:52 GMT |
Viewport: width=device-width,initial-scale=1