简体   繁体   English

谁能告诉我这个 javaScript function 是如何工作的?

[英]Can anyone tell me how this javaScript function works please?

I am a beginner and recently I have stumbled onto this.我是一个初学者,最近我偶然发现了这个。 I do not understand what this d.getDays() does.我不明白这个d.getDays()做了什么。 Please help me out.请帮帮我。

 const dateBuilder = (d) => { let months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] let day = days[d.getDay()]; let date = d.getDate(); let month = months[d.getMonth()]; let year = d.getFullYear(); return `${day} ${date} ${month} ${year}` } console.log(dateBuilder(new Date()));

It's a method of the Date object that returns a number representing the day of the week (Monday, Tuesday etc.) that correlates to the days array you have in your code.它是Date object 的一种方法,它返回一个代表星期几(星期一、星期二等)的数字,该数字与代码中的days数组相关。 Read more here . 在这里阅读更多。 It's basically getting the "name" of the day by using that array days :它基本上是通过使用该数组days获得当天的“名称”:

let days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]

It seems that d is a Date object. d 似乎是一个日期object。

getDay() is a method being called on that object. getDay()是在 object 上调用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 谁能告诉我这是如何工作的? - Can anyone tell me how this works? 有谁可以告诉我如何执行此自定义javascript函数? - Does anyone can tell me how this custom javascript function to execute? 谁能解释一下“ if(blnRtrn == true)”的工作原理吗? - Can anyone please explain me how this “if (blnRtrn == true)” works? 任何人都可以从 eloquent javascript 中向我解释以下函数 - Can anyone please explain me the following function from eloquent javascript 有人可以告诉我如何删除或隐藏此 JavaScript 代码吗? - Can someone please tell me how to remove or hide this JavaScript code? 谁能告诉我这个功能是做什么的? - Can anyone please tell me what does this funciton do? 谁能告诉我这个套接字事件有什么问题? - Can anyone please tell me what's wrong this socket event? 谁能告诉我为什么这个javascript函数调用不起作用? - Can anyone tell me why this javascript function call isn't working? 有人可以告诉我为什么此Javascript打印订单摘要功能未运行吗? - Can someone please tell me why this Javascript print order summary function is not running? 谁能告诉我,如何使用 Java 脚本代码将下面的 html 下拉值保存到表格中 - Can anyone please tell me, how to save below html drop down values into table by using Java script Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM