`
jasin2008
  • 浏览: 69333 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

摘录《professional javascrpt for web developers》

    博客分类:
  • js
阅读更多
摘录《professional javascrpt for web developers》
p17:
Calling typeof on a variable or value returns one of the following values:
❑ “undefined” if the variable is of the Undefined type.
❑ “boolean” if the variable is of the Boolean type.
❑ “number” if the variable is of the Number type.
❑ “string” if the variable is of the String type.
❑ “object” if the variable is of a reference type or of the Null type.

p142:
The window.open() method returns a window object as its function value that is also the window object
for the newly created window (or for the frame, if the name given is the name of an existing frame).
Using this object, it’s possible to manipulate the new window:
var oNewWin = window.open(“http://www.wrox.com/”, “wroxwindow”,
“height=150,width=300,top=10,left=10,resizable=yes”);
oNewWin.moveTo(100, 100);
oNewWin.resizeTo(200, 200);

Also using this object, it is possible to close the new window using the close() method:
oNewWin.close();


p184:
To create a NodeIterator object, use the createNodeIterator() method of the document object. This
method accepts four arguments:
1. root — the node in the tree that you wish to start searching from
2. whatToShow — a numerical code indicating which nodes should be visited
3. filter — a NodeFilter object to determine which nodes to ignore
4. entityReferenceExpansion — a Boolean value indicating whether entity references should
be expanded
You can combine multiple values by using the bitwise OR operator:
var iWhatToShow = NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT;

The filter argument of createNodeIterator() can be used to specify a custom NodeFilter object, but
can also be left null if you don’t want to use it.
To create a simple NodeIterator that visits all node types, use the following:
var iterator = document.createNodeIterator(document, NodeFilter.SHOW_ALL, null,
false);


p305:
DOM style methods
The DOM also described several methods for the style object, all designed to interact with individual
parts of the CSS style definition:
❑ getPropertyValue(propertyName) — Returns the string value of the CSS property
propertyName. The property must be specified in CSS style, such as “background-color”
instead of “backgroundColor”.
❑ getPropertyPriority() — Returns the string “important” if the CSS property
“!important” is specified in the rule; otherwise it returns an empty string
❑ item(index) — Returns the name of the CSS property at the given index, such as
“background-color”
❑ removeProperty(propertyName) — Removes propertyName from the CSS definition
❑ setProperty(propertyName, value, priority) — Sets the CSS property propertyName
to value with the given priority (either “important” or an empty string)

p388:
Dragged item events
When an item is dragged, the following events fire (in this order):
1. dragstart
2. drag
3. dragend
At the moment you hold a mouse button down and begin to move the mouse, the dragstart event
fires on the item that is being dragged. By default, this event fires on an image or text selection being
dragged. The cursor changes to the no-drop symbol (a circle with a line through it) indicating that the
item cannot be dropped on itself. You can use the ondragstart event handler to run JavaScript code as
the dragging begins.
After the dragstart event fires, the drag event fires and continues firing so long as the object is being
dragged. You can think of this event as similar to mousemove (which also fires repeatedly as the mouse is
moved). When the dragging stops (because you drop the item onto either a valid or invalid drop target)
the dragend event fires.

p393:
The dataTransfer object
Simply dragging and dropping isn’t of any use unless data is actually being affected. To aid in the transmission
of data via drag and drop, Internet Explorer 5.0 introduced the dataTransfer object, which
exists as a property of event and is used to transfer string data from the dragged item to the drop target
(the dataTransfer object is still used in IE 6.0).
393
Drag and Drop
Because it is a property of event, the dataTransfer object doesn’t exist except within the scope of an
event handler, specifically, an event handler for a drag-and-drop event. Within an event handler, you can
use the object’s properties and methods to work with your drag-and-drop functionality.

The dataTransfer object has two methods: getData() and setData(). As you might expect,
getData() is capable of retrieving a value stored by setData(). Two types of data can be set: plain text
and URLs. The first argument for setData(), and the only argument of getData(), is a string indicating
which type of data is being set, either “text” or “URL”. For example:
oEvent.dataTransfer.setData(“text”, “some text”);
var sData = oEvent.dataTransfer.getData(“text”);
oEvent.dataTransfer.setData(“URL”, “http://www.wrox.com/”);
var sURL = oEvent.dataTransfer.getData(“URL”);
It should be noted that two spaces can be used to store data: one for text and one for a URL. If you make
repeated calls to setData(), you are always overwriting the data stored in the space specified.
The data stored in the dataTransfer object is only available up until the drop event. If you do not
retrieve the data in the ondrop event handler, the dataTransfer object is destroyed and the data is lost.

dropEffect and effectAllowed
The dataTransfer object can be used to do more than simply transport data to and fro; it can also be
used to determine what type of actions can be done with the dragged item and the drop target. You
accomplish this by using two properties: dropEffect and effectAllowed.
395
Drag and Drop
The dropEffect property is set on the drop target to determine which type of drop behavior is allowed.
These are four possible values:
❑ “none” — A dragged item cannot be dropped here. This is the default value for everything but
text boxes.
❑ “move” — Indicates that the dragged item should be moved to the drop target.
❑ “copy” — Indicates that the dragged item should be copied to the drop target.
❑ “link” — Indicates that the drop target will navigate to the dragged item (but only if it is a URL).
Each of these values causes a different cursor to be displayed when an item is dragged over the drop
target. It is up to you, however, to actually cause the actions indicated by the cursor. In other words,
nothing is automatically moved, copied, or linked without your direction intervention. The only thing
you get for free is the cursor change. In order to use the dropEffect property, it must be set in the
ondragenter event handler for the drop target.
The dropEffect property is useless unless you also set the effectAllowed property on the dragged
item. This property indicates which dropEffect is allowed for the dragged item. The possible values
are the following:
❑ “uninitialized” — No action has been set for the dragged item.
❑ “none” — No action is allowed on the dragged item.
❑ “copy” — Only dropEffect “copy” is allowed.
❑ “link” — Only dropEffect “link” is allowed.
❑ “move” — Only dropEffect “move” is allowed.
❑ “copyLink” — dropEffects “copy” and “link” are allowed.
❑ “copyMove” — dropEffects “copy” and “move” are allowed.
❑ “linkMove” — dropEffects “link” and “move” are allowed.
❑ “all” — All dropEffects are allowed.
This property must be set inside the ondragstart event handler.

p405:
zDragDrop
You’ve seen that simulating drag and drop takes a fair amount of JavaScript. You may be wondering,
“Isn’t there some sort of JavaScript library that handles all this for me?” The answer is the zDragDrop
library, freely available from http://www.nczonline.net/downloads/. This library provides a set of
objects that encapsulate much of the simulated drag-and-drop process. You need only include the file
zdragdroplib.js in your page to take advantage of the functionality.

p423:
zDragDrop
You’ve seen that simulating drag and drop takes a fair amount of JavaScript. You may be wondering,
“Isn’t there some sort of JavaScript library that handles all this for me?” The answer is the zDragDrop
library, freely available from http://www.nczonline.net/downloads/. This library provides a set of
objects that encapsulate much of the simulated drag-and-drop process. You need only include the file
zdragdroplib.js in your page to take advantage of the functionality.

p426:
The third edition of ECMAScript also introduced the throw statement to raise exceptions purposely. The
syntax is the following:
throw error_object;
The error_object can be a string, a number, a Boolean value, or an actual object. All the following
lines are valid:
throw “An error occurred.”;
throw 50067;
throw true;
throw new Object();
It is also possible to throw an actual Error object. The constructor for the Error object takes only one
parameter, the error message, making it possible to do the following:
throw new Error(“You tried to do something bad.”);
All the other classes of Error are also available to developers:
throw new SyntaxError(“I don’t like your syntax.”);
throw new TypeError(“What type of variable do you take me for?”);
throw new RangeError(“Sorry, you just don’t have the range.”);
throw new EvalError(“That doesn’t evaluate.”);
分享到:
评论

相关推荐

    JavaScrpt DOMscripting编程艺术

    JavaScript DOM脚本编程艺术主要涉及的是使用JavaScript与文档对象模型(DOM)进行交互的技术,它在Web开发中占据着核心地位。DOM是HTML和XML文档的结构化表示,允许我们通过编程方式访问和修改页面元素。以下是这个...

    javaScrpt效果大师 pdf版

    javaScrpt 效果 大师 pdf 欢迎大家下载

    javascrpt 打字效果逐条

    JS 打字效果逐条\javascrpt 打字效果逐条

    My97DatePicker.rar(javaScrpt时间控件)

    My97DatePicker.rar(javaScrpt时间控件) 可以在多浏览器运行。。如IE和Mozilla Firefox运行 可以在jsp,asp,asp.net,php项目中使用实现无刷。。。

    Javascrpt 高级程序设计第3版(超清中文版750页)

    前端开发必备,真正的超清,Javascrpt 高级程序设计第3版(超清中文版750页)本书从最早期Netscape浏览器中的JavaScript开始讲起,直到当前它对XML和Web服务的具体支持,内容主要涉及JavaScript的语言特点、...

    Javascrpt高级程序设计

    本书是 JavaScript 超级畅销书的最新版。...专有实现和客户端扩展正式进入规范, 同时也为 JavaScript 增添了很...本书适合有一定编程经验的 Web 应用开发人员阅读, 也可作为高校及社会实用技术培训相关专业课 程的教材。

    ArcGIS API for JavaScript 4.14 进阶之空间分析(附源码)

    ArcGIS API for JavaScript 4.14 空间分析(本示例展示了空间分析的包含关系,控制缓冲区内点位的显隐)

    JavaScrpt

    JavaScript是一种广泛应用于网络开发的脚本语言,主要在浏览器环境中执行,用于实现客户端的动态交互。它赋予网页活力,使得用户在浏览时可以有更丰富的体验。JavaScript语法基于ECMAScript规范,其最新版本为...

    ext 3.2.0 javascrpt框架

    ext 3.2.0 源码哟。。。 做漂亮的web...

    thrift web实例代码

    thrift web实例代码。使用thrift js时,PRotocol需要使用TJSONPRotocol/TBinaryProtocol协议,Thrift.Protocol对应的是TJSONPRotocol。Transport需要使用TXHRTransport/TWebSocketTransport通道,Thrift.Transport...

    javascrpt原理

    JavaScript原理详解 ...JavaScript的动态性、灵活性以及丰富的库和框架使其在Web开发中占据重要地位,同时也带来了独特的挑战,因此,理解其底层运作机制对于成为一个优秀的JavaScript开发者至关重要。

    javascrpt小课程项目

    【JavaScript小课程项目】是一个专为初学者设计的实践教程,旨在帮助他们初步掌握JavaScript的基础知识和实际应用。...通过完成这个项目,你将具备创建基本Web交互功能的能力,为进一步深入学习前端开发打下坚实基础。

    javascrpt语言精粹.doc

    - **循环**:`while`、`for` 和 `do...while` 循环结构用于重复执行代码块。 - `for in` 循环用于遍历对象的属性。 - **跳转语句**:`break`、`return` 和 `throw` 用于控制流程跳出当前循环或函数。 #### 1.5.1...

    JavaScrpt表单验证大全

    JavaScript是Web开发中不可或缺的一部分,尤其在前端交互和数据验证方面扮演着重要角色。"JavaScript表单验证大全"集合了各种表单验证方法和源码,旨在帮助开发者创建美观且功能强大的表单验证机制,提高用户体验,...

    javascrpt的一些书籍

    了解这些机制对于编写高性能的Web应用非常重要。 5. **DOM操作**:JavaScript与HTML的交互主要通过Document Object Model(DOM)实现。学习如何创建、修改和查找DOM元素,以及如何监听和触发事件,是前端开发的基础...

    javascrpt functional in es6

    ES6(ECMAScript 6)是JavaScript语言的一个重要版本,也称为ECMAScript ...通过这些知识,开发者可以更好地理解如何编写高效、可读、可维护的JavaScript代码,这对于任何一个从事Web开发的程序员来说都是必备的技能。

    web初学者最好的实例

    在web开发领域,实例是学习和提升技能的重要途径。"web初学者最好的实例"这个压缩包文件为你提供了一个丰富的实践平台,涵盖了多个关键知识点,帮助初学者快速掌握web开发的核心技术。下面,我们将深入探讨这些关键...

Global site tag (gtag.js) - Google Analytics