javascript ++_C ++开发人员如何学习JavaScript:一个令人沮丧但最终令人满意的故事...

javascript ++

by DHARA DOSHI

通过DHARA DOSHI

C ++开发人员如何学习JavaScript:一个令人沮丧但最终令人满意的故事 (How a C++ developer learns JavaScript: a frustrating but ultimately satisfying tale)

This year I started my journey into Web Development. As the umpteenth article on the web will profess: JavaScript is the holy grail.

今年,我开始了Web开发之旅。 正如网络上的第十篇文章所宣称的那样:JavaScript是圣杯。

And so I began my journey into this new stack, new domain, and a whole new level of newness.

因此,我开始了进入新堆栈,新域和全新水平的旅程。

So, in the middle of the day, in the middle of a feature I was implementing, I was almost at the stage where I felt like pulling my hair out. My frustration knew no bounds, and my impostor syndrome was at an all time high.

因此,在一天当中,我正在实施的功能中,我几乎处于要拔头发的阶段。 我的挫败感无止境,我的冒名顶替综合症空前高涨。

Before I tell you any more about what issue nearly turned me insane, let me give a bit of a background about myself.

在我进一步告诉您什么问题几乎使我发疯之前,让我先介绍一下自己的背景。

I have basically just started scratching the surface of JavaScript, and have taken a few FreeCodeCamp lessons (and have marveled at what Quincy Larson has accomplished). Since the time I started my journey as a Computer Science graduate more than 10 years ago, I’ve never seen coding being taught in such a structured manner before.

我基本上才刚刚开始学习JavaScript的知识,并学了一些FreeCodeCamp课程(并对Quincy Larson的成就感到惊讶)。 自从我10多年前以计算机科学专业毕业生的身份开始我的旅程以来,我从未见过以这种结构化的方式来教授编码。

I started JavaScript development in February 2018 (after I took a course with edX on JavaScript & JQuery, called Programming for the Web with JavaScript). This means I have been at it for five months now. I am strangely indignant that I got stuck on this issue now rather than a few months back, but a developer hardly has an choice with things like that. You just have to swallow your ego, every freaking time. And learn!

我于2018年2月开始JavaScript开发(在edX上JavaScript&JQuery课程之后,该课程称为``使用JavaScript 进行网络编程'' )。 这意味着我已经参加了五个月。 令我感到奇怪的是,我现在就停留在这个问题上,而不是几个月前,但是对于这样的事情,开发人员几乎别无选择。 您只需要在每一次疯狂的时刻都吞下自己的自我。 和学习!

Are you wondering what specific JavaScript issue made me ask all existential questions in my life?

您是否想知道什么特定JavaScript问题使我提出了生活中所有存在的问题?

星期一先生的插图故事,按钮。 (An illustrated story of Mr. Monday, the button.)

This is the story of a button:

这是一个按钮的故事:

Mr. Monday’s personality can be defined as:

星期一先生的人格可以定义为:

<button type=”button” class=”btn btn-sm btn-success” id=”<mon-week-day”>MON</button>

But Mr. Monday isn’t as original as we want him to be. He was based on a template, and the source of his real personality was something like this:

但是星期一先生并不像我们希望的那样原始。 他基于一个模板,而他真实个性的来源是这样的:

<button type=”button” class=”btn btn-sm btn-success” id=”<%=day%>-week-day”>day.substr(0, 3).toUpperCase()</button>
where day is the days of the week: monday, tuesday, wednesday etc.

Disclaimer: The code is <%= day %&gt; is EJS.

免责声明:代码为<%=天%&g t; 是EJS。

I wanted to give Mr. Monday’s personality a shade of gray in some situations.

在某些情况下,我想给星期一先生的个性打上灰色阴影。

But Mr. Monday just didn’t know how to have any fun. Sigh! He wouldn’t turn gray!

但是星期一先生只是不知道该怎么玩。 叹! 他不会变灰!

我如何终于在星期一先生身上发挥出最好的作用 (How I finally brought out the best in Mr. Monday)

I said to him let’s do this, so let me groom you to add class to your persona.

我对他说,让我们这样做,所以让我修饰您,以增加您的角色的类。

$('#'+day+'week-day').addClass('unselected')

He didn’t budge. I changed the addClass to toggleClass and still nothing happened. I think he wasn’t keen about being ‘unselected’, though I explained to him why it was essential.

他没有让步。 我将addClass更改为toggleClass,仍然没有任何React。 我认为他并不热衷于“未被选中”,尽管我向他解释了为什么这样做很重要。

Then I brought out the big guns, the console. And I tried to change him there. The console threw some doubt on Mr. Monday’s capability to turn.

然后我拿出了大枪,控制台。 我试图在那里改变他。 控制台对周一先生的转弯能力提出了一些疑问。

It would say that it changed the color, but I would still see a very green Mr. Monday. So what was happening here? My Sherlock mind came to my rescue and voilà, I realized the biggest mistake ever know to mankind in the history of programming (or at least in my mind it appeared like the biggest screw up ever).

它会说它改变了颜色,但是星期一我仍然会看到一个非常绿色的先生。 那么这里发生了什么? 我的Sherlock头脑浮出了水面,我意识到了人类编程史上最大的错误(或者至少在我看来,这是有史以来最大的错误)。

There was another element with the same id as Mr. Monday. This was why he wouldn’t budge and all the changes were probably being targeted to the other guy. An acute case of identity crisis, I must say!

还有另一个元素与星期一先生具有相同的编号。 这就是为什么他不会让步并且所有更改都可能针对另一个人的原因。 我必须说一个严重的身份危机案例!

How did this happen? Well, have you heard of the phrase “Too many cooks spoil the broth?” That’s what happened: two or three people had worked on the same file before, and somehow this new id matched with one of the id’s they had used before for an element. Phew, this was such an important lesson for me.

这怎么发生的? 好吧,您是否听说过“太多的厨师把汤糟了?” 就是这样:两三个人以前曾在同一个文件上工作过,所以这个新的id与他们以前用于某个元素的一个id相匹配。 ew,这对我来说是非常重要的一课。

All elements should have unique ids.

所有元素都应具有唯一的ID。

Anyway, I changed Mr. Monday’s id, and tried again.

无论如何,我更改了星期一先生的身份证,然后再试一次。

<button type=”button” class=”btn btn-sm btn-success” id=”<monday-hours-day”>MON</button>
$('#'+day+'hours-day').addClass('unselected')

And still, Mr. Monday wouldn’t turn gray.

不过,星期一先生不会变灰。

解决有史以来最大的错误 (Fixing the biggest mistake ever)

After a few hours of googling, wondering if this really was what I wanted to do for the rest of my life (eyeballs almost out of my eye sockets trying to find ways to turn Mr. Monday gray), I figured out what the problem was.

搜查了几个小时后,想知道这是否真的是我一生想要做的事情(眼球几乎从我的眼窝里出来,试图找到使星期一先生变灰的方法),所以我找出了问题所在。

And I know you are dying to find out. I promise when you know, you’ll hate me for making the silliest mistake in human history.

而且我知道您想找出答案。 我保证,当您知道时,您会恨我犯下人类历史上最严重的错误。

The problem was that I missed a ‘-’(hyphen) in the id before hours, when adding class unselected.

问题是在添加未选择的类时,我在小时前错过了ID中的'-'(连字符)。

$('#'+day+'hours-day').addClass('unselected')//is clearly wrong.
$('#'+day+'-hours-day').addClass('unselected') //is the perfect code ever

Mr. Monday finally turned gray! This gave me such immense happiness I slept like a puppy that day! Yes, just like the one in this picture.

星期一先生终于变灰了! 这给了我极大的快乐,那天我像小狗一样睡着了! 是的,就像这张照片中的那个一样。

To read more stories about my escapades in code land, please motivate me by clicking on the ‘Applause’/’Claps’ icon multiple times — ideally 50, but if you are as lazy as I am, I’ll accept 20 of them (Nothing less than that please ;) ).

要阅读有关我在代码保护区中出逃的更多故事,请通过多次单击“掌声” /“拍手”图标激励我-理想情况下为50,但如果您像我一样懒,我会接受其中的20(没什么比请;))。

Originally published at www.heisenbugtech.com

最初发布在www.heisenbugtech.com

翻译自: https://www.freecodecamp.org/news/tales-of-a-c-developer-learning-javascript-96b0a3324d25/

javascript ++

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值