Home > Web Front-end > JS Tutorial > body text

Get out of the JavaScript beginner's dilemma—js beginner_basic knowledge

WBOY
Release: 2016-05-16 18:56:55
Original
696 people have browsed it

从开始接触JS这东西有一年时间了,心头总是有一些说不出来的苦闷。在论坛里也常常有人这么说。那么苦在何处呢?总是感觉学的不深入,一些简单的东西可以做但也是不能得心应手。能不能把这种苦再说的具体点儿呢?都说了是“说不出来的苦闷”怎么具体呀?

何为难言之隐?说不出来,不能具体,不能把问题落到实处就不能得到解决的办法。这就是难言之隐!我认为这也就是初学者的“困境”。之所以要用“我认为”正好迎合了本文标题中的“心得”二字。如果能对大家有帮助我非常高兴。

下面言归正传,我经过回想和思考总结出下面几条初学者的“难言之隐”大家看看有没有说到我们的心坎儿上,呵呵。

一、用系统的知识将问题具体化

我们在学习时经常会发现可以用不同的方法来实现同一个问题。例如,要为元素绑定一个点击事件可以在HTML元素上用,我们起初会认为这就是绑定事件的方法。

当我们第二次又看到可以将一个函数传递给一个事件来绑定:a.onclick=f1;这时我们又会想原来绑定事件不只有一种方法。

当我们第三次又看到用addachEvent("onclick",f1)这种方法绑定事件的时候,你一定会想绑定事件的方法可能不只这三种。而且做一件事没理由要三种相同的方法,他们之间一定有不同之处?

那么他们有什么不同之处呢?到底绑定事件有多少种方法呢?当你发现一种方法在IE中不兼容的时候你还会问这到底是为什么呢?是我的语法错误了吗?还是怎么回事。一个又一个的问题结束之后你只好问自己:“天呀!我什么时候才能学好JavaScript呢?!“。

可能这样下去你很难学好JS。其实还要告诉你,你离学好他并不远了,只是你不知道怎么走。原因在哪里?原因就是没有系统的知识,原因就是没有读过《JavaScript权威指南》,他会告诉你绑定事件有四种方法,并且有两种是基本方法,所有浏览器都支持他,另外还有两种高级方法,一种是W3C标准方法,一种是IE标准方法,所以你知道为什么IE不兼容其中的一种高级方法了,对吗?

现在事情具体化了,绑定一个事件的时候只需考虑这四种方法,你也不会再有那么多的疑惑了。你也会觉得自己弄懂事件了,下一步你应该去弄懂其它问题了,你还会觉得自己在JS方面终于有进展了,当然你还会感觉到走出一个困境了。

二、必需了解JavaScript的历史

你了解JS的历史吗?我当然了解,他原本不叫JavaScript,他最早不是实现在IE中的。对,说的很好,可这不是最重要的,知道这个也不会成为高手,你必须了解的更详细,而且主要是了解功能进化方面的历史。

就像上面,为什么绑定事件会有那多的方法?为什么获得一个元素会有那么多的方法?倒底是document.links[]正规一点?还是getElementsByTagName('a')正规一点?哪一个兼容性更好?还有多少这样的方法?

要知道一个问题就够头痛了,十个问题你就无从下手,一百个问题你就会怀疑自己。一千个问题最后又回到那个问题“天呀!我什么时候才能学好JavaScript“?呵呵,事情往往就是这样。解决的方法就是具体化他,去弄懂到底有几种方法,为什么又有这些方法。这些问题一定会有答案,因为JS不是外星人留下的东西,是人创造出来的,而那个人的思维也是有限的,不是吗?

当你知道document.links[]是遗留的document方法,而且这种遗留方法一共有5个。分别是anchors[],applets[],forms[],images[],links[]的时候有些问题就消失了,当你还知道DOM标准保留了他们,你还知道所有浏览器都支持他们,你还知道他们就是所谓的“0级DOM”你又会走出一个“困境”。

三、JS有纵横交错的知识结构

JS的知识结构是横向和纵向交错的,这加大了理解他的难度,对这一点必需有一个清晰的认识。下面解释一下“纵横交错”。

一般的知识都有横向性。比如从大的方面JS分为核心部分和客户端部分。这是横向。核心部分又分为词法结构,数据类型和值,变量,表达式和运算符,语句,对象和数组,函数,类,模块和名字空间,正则表达式。这也是横向。

客户端部分可以分为BOM,DOM,事件,样式,表单等,这些也是横向的知识结构。

A technology rarely uses time as a structure, but because the development of browsers is dynamic, browsers in different periods have different levels of implementation of JS, and web pages written for the browsers at that time at different times cannot be changed because of The development of technology should not be taken into consideration, and it is impossible for all websites to be rewritten with the development of technology. Therefore, JS must be developed and upgraded while retaining forward support. So even if there is a better method, the previous method must be retained. There are many legacy JS properties and methods. For example, the "level 0 DOM" has been retained in the new W3CDOM. To a certain extent, it is vertical of.

When I have a clear understanding of the knowledge structure, one benefit is that when I want to solve a problem, I can know which piece of knowledge I want to use. For example, if you want to get the position of an element in the document, you will know to use the attributes of the element in the DOM. If you want to get the position of the mouse pointer, you will use the attributes of the event object. To obtain a reference to an element, you can use the legacy DOM or the W3C standard DOM method. This is a good thing.

In fact, the core of the above question is systematization and concreteness, which is something I think is very important in the learning process. This really solved a lot of doubts for me.

To get out of the beginner’s dilemma, we need systematic knowledge and concrete thoughts. Thank you for taking the time to read this article. I hope it will be helpful to you. If you want to discuss more issues, please add me on QQ: 303551651.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!