javascript 编码_JavaScript改变我编码方式的4种方式

javascript 编码

The plot: I started teach myself web programming ten years ago; about three years ago I became infatuated with JavaScript and its practices. The bad news: in teaching myself I developed my own bad habits. The good news: my time with JavaScript and the MooTools team has opened my eyes to a better way of coding. Here are a few ways JavaScript has helped me to become a better programmers.

剧情:十年前,我开始自学Web编程。 大约三年前,我迷上了JavaScript及其实践。 坏消息:在自学中我养成了自己的坏习惯。 好消息:我在JavaScript和MooTools团队工作的时光使我对更好的编码方式大开眼界。 以下是JavaScript帮助我成为更好的程序员的几种方法。

我希望一切都成为一个对象(为您拧PHP!) (I Want Everything to be an Object (Screw You PHP!))

Before my love affair with PHP, I was content with using static functions for everything. I had no problem with:

在与PHP恋爱之前,我很满足于对所有内容使用静态函数。 我没问题:


$result = explode(';',$text);
echo $result[0];
//or....
list($title,content) = explode(';',$text);
echo $title;


Now I vomit every time I have to code something like that. I love that JavaScript's "everything's an object" philosophy allows me to quickly string together a billion operations:

现在,我每次必须编写类似的代码时都会呕吐。 我喜欢JavaScript的“一切都是对象”的哲学,使我能够快速进行十亿次运算:


var myText = $('myElement').getFirst('a').get('text').split('.')[0].replace(' ','-');


JavaScript FTW!

JavaScript FTW!

I CamelCase(拧下划线!) (I CamelCase (Screw You Underscore!))

I generally try to conform to the philosophies of any language when it comes to naming variable and functions. While many would argue PHP can't make up its damn mind about such matters, I would say PHP's standard is the underscore. Since I've coded so much JavaScript over the past few years, I've come to prefer camelcasing. Same readability, a few less characters.

在命名变量和函数时,我通常会尝试遵循任何语言的哲学。 尽管许多人认为PHP无法在这类事情上下定决心,但我要说PHP的标准是强调。 由于在过去的几年中我编写了很多JavaScript,因此我开始更喜欢骆驼式包装。 可读性相同,字符少了一些。

JavaScript FTW!

JavaScript FTW!

相同行{用于功能(拧Pascal!) (Same-Line { for Functions (Screw You Pascal!))

My first inclination as a n00b programmer when it came to braces was that they should be given their own line:

作为括号,我作为n00b程序员的初衷是给他们自己的一行:


function my_function($x)
{
	if($x) 
	{
		//..stuff
	}
	else
	{
		//..stuff
	}
}


I probably thought that the extra whitespace made the code easier to read. Now I'm just annoyed with beginning braces having their own line. Seems like a waste of space.

我可能以为多余的空格使代码更易于阅读。 现在,我对刚开始使用大括号的人感到恼火。 似乎是在浪费空间。

JavaScript FTW!

JavaScript FTW!

我需要框架(向您推荐Vanilla PHP!) (I Require Frameworks (Screw You Vanilla PHP!))

Remember the days when people would scour the web for JavaScript components and hack together their website? I recently ran into a company that did that. Sick. Frameworks like MooTools make coding a billion times faster. Your code becomes more consistent and many components are in place for you. Working without a framework is like going into a brothel without protection.

还记得人们曾经在网上搜寻JavaScript组件并入侵他们的网站的日子吗? 我最近遇到了一家这样做的公司。 生病。 MooTools之类的框架使编码速度提高了十亿倍。 您的代码变得更加一致,并且为您准备了许多组件。 没有框架的工作就像进入没有保护的妓院。

JavaScript FTW!

JavaScript FTW!

So that's how JavaScript has changed the way I code. Am I missing something? Have a similar experience? Let me know!

这就是JavaScript改变我编码方式的方式。 我想念什么吗? 有类似的经历吗? 让我知道!

翻译自: https://davidwalsh.name/ways-javascript-changed-code

javascript 编码

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值