473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

David Flanagan's 5th edition *JavaScript*

>From Flanagan's javascript: The Definitive Guide 5th edition.
1.1.2 JavaScript is Not Simple

Programmers who attempt to use JavaScript for nontrivial tasks
often find the process frustrating if they do not have a solid
understanding of the language.

1.2 Versions of JavaScript

Any browsers newer than Netscape 4.5 or Internet Explorer 4
supports
the latest version of the language. As a practical matter, you are
unlikely to encounter a noncompliant interpreter.

8.1.3 Naming Functions

The client-side JavaScript framework Prototype
(http://prototype.conio.net), elegantly uses the function $()
(yes, just a dollar sign) as an intelligent replacement
for the very common but hard-to-type document.getElementById().

9.2.2 Extending Built-in Types

There is a strong argument against extending built-in types with
your
own methods; if you do so, you are essentially creating your own
custom
version of the core JavaScript API. Any other programmers who have
to
read or maintain your code will likely find it confusing if your
code
includes methods they have never heard of. Unless you are creating
a low-level JavaScript framework that you expect to be adopted by
many
other programmers, it is probably best to stay away from prototype
objects
of the built in types.

Note that you must _never_ add properties to Object.prototype. Any
properties or methods you add are enumerable with a for/in loop,
and
adding them to Object.prototype makes them visible in every single
JavaScript object. An empty object, {}, is expected to have no
enumerable
properties. Anything added to Object.prototype becomes an
enumerable
property of the empty object and will likely break code that uses
objects as associative arrays.

9.6 Extending Without Inheriting

function borrowMethods(borrowFrom, addTo) {
var from = borrowFrom.prototype // prototype object to borrow
from
var to = addTo.prototype // prototype object to extend

for(m in from) {
if (typeof from[m] != "function") continue; // ignore
nonfunctions
to[m] = from[m]; //borrow the method
}
}

9.7.3 Duck Typing

Example 9-8 Testing whether an object provides methods

// Return true if o has methods with the same name and arity as all
// methods in c.prototype. Otherwise, return false. Throws and
exception
// if c is a built in type with nonenumerable methods.
function provides(o, c) {

9.8 Example: A defineClass() Utility Method

* After the prototype object is fully initialized, this function
* verifies that the prototype includes methods whose names and
* number of arguments match the instance methods defined by each
* of these classes. No methods are copied; this is simply an
* assertion that this class "provides" the functionality of the
* specified classes.

10.1 Creating Modules and Namespaces

In this code, the global flanagan object is a namespace for
namespaces.

10.2 Importing Symbols from Namespaces

After loading the com.davidflanagan.Class module, for example, a
user
of that module might write the following:

// This is an easier name, to save typing.
var define = com.davidflanagan.Class.define

It is the module developers responsibility to use namespaces to
prevent
collisions. But it is the module user's prerogative to import
symbols from
the module's namespace into the global namespace.

Sep 12 '06 #1
3 1730
[That could look a lot nicer in google groups. Try again...]
>From Flanagan's javascript: The Definitive Guide 5th edition.

1.1.2 JavaScript is Not Simple

Programmers who attempt to use JavaScript for nontrivial tasks often
find the process frustrating if they do not have a solid understanding
of the language.

1.2 Versions of JavaScript

Any browsers newer than Netscape 4.5 or Internet Explorer 4 supports
the latest version of the language. As a practical matter, you are
unlikely to encounter a noncompliant interpreter.

8.1.3 Naming Functions

The client-side JavaScript framework Prototype
(http://prototype.conio.net), elegantly uses the function $() (yes,
just a dollar sign) as an intelligent replacement for the very common
but hard-to-type document.getElementById().

9.2.2 Extending Built-in Types

There is a strong argument against extending built-in types with your
own methods; if you do so, you are essentially creating your own custom
version of the core JavaScript API. Any other programmers who have to
read or maintain your code will likely find it confusing if if your
code includes methods they have never heard of. Unless you are creating
a low-level JavaScript framework that you expect to be adopted by many
other programmers, it is probably best to stay away from prototype
objects of the built in types.

Note that you must _never_ add properties to Object.prototype. Any
properties or methods you add are enumerable with a for/in loop, and
adding them to Object.prototype makes them visible in every single
JavaScript object. An empty object, {}, is expected to have no
enumerable properties. Anything added to Object.prototype becomes an
enumerable property of the empty object and will likely break code that
uses objects as associative arrays.

9.6 Extending Without Inheriting

function borrowMethods(borrowFrom, addTo) {
var from = borrowFrom.prototype // prototype object to borrow
from
var to = addTo.prototype // prototype object to extend

for(m in from) {
if (typeof from[m] != "function") continue; // ignore
nonfunctions
to[m] = from[m]; //borrow the method
}
}

9.7.3 Duck Typing

Example 9-8 Testing whether an object provides methods

// Return true if o has methods with the same name and arity as all
// methods in c.prototype. Otherwise, return false. Throws and
exception
// if c is a built in type with nonenumerable methods.
function provides(o, c) {

9.8 Example: A defineClass() Utility Method

* After the prototype object is fully initialized, this function
* verifies that the prototype includes methods whose names and
* number of arguments match the instance methods defined by each
* of these classes. No methods are copied; this is simply an
* assertion that this class "provides" the functionality of the
* specified classes.

10.1 Creating Modules and Namespaces

In this code, the global flanagan object is a namespace for namespaces.

10.2 Importing Symbols from Namespaces

After loading the com.davidflanagan.Class module, for example, a user
of that module might write the following:

// This is an easier name, to save typing.
var define = com.davidflanagan.Class.define

It is the module developers responsibility to use namespaces to prevent
collisions. But it is the module user's prerogative to import symbols
from the module's namespace into the global namespace.

Sep 12 '06 #2
pe**********@gmail.com wrote:
>>From Flanagan's javascript: The Definitive Guide 5th edition.
<snip>
the module's namespace into the global namespace.
But the 4th edition was not without its faults, which is why it took so
long to for any javascript book to be endorsed by the group. Endorsing
the least bad book available was not an entirely popular choice.

Listing the more obvious faults in the book does not say much about the
remaining material, or their proportion in the full contents.

Richard.
Sep 12 '06 #3

Richard Cornford wrote:
pe**********@gmail.com wrote:
>From Flanagan's javascript: The Definitive Guide 5th edition.
<snip>
the module's namespace into the global namespace.

But the 4th edition was not without its faults, which is why it took so
long to for any javascript book to be endorsed by the group. Endorsing
the least bad book available was not an entirely popular choice.

Listing the more obvious faults in the book does not say much about the
remaining material, or their proportion in the full contents.

Richard.
I wasn't implying these were faults. I'm glad to read all of them and
think some of them are very good ideas. These were the sections that
caught my eye and express some philosophy on JavaScript use. Perhaps
these show how Flanagan may see the future of JavaScript. He certainly
has extended discussions of class-based inheritance and the idea of
enforcing Java-like interfaces. Also private properties and namespaces
recieve good treatment. I think he sees JavaScript applications getting
quite large with a number of different developers sharing code. An
environment that requires more language enforced safety similar to
Java.

I just read the AJAX chapter and really enjoyed it. Not that I have
much experience writing AJAX libraries but it was an easy to read
introduction.

Peter

Sep 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dung Ping | last post by:
I was ready to order his Definitive Guide, 4th ed., but noticed it was revised in 2001. Is there a way to find out whether a new edition of it is coming out soon? If yes, I will wait a bit for...
2
by: petermichaux | last post by:
Hi, Just found this announcement from May 4th that JavaScript: The Definitive Guide 6th ed will be available soon. http://www.davidflanagan.com/ Peter
19
by: firewood | last post by:
Just got a copy of the 5th edition of David Flangan's "JavaScript: The Definitive Guide". It looks, a first scan, to be superb. It will continue, I am sure, to be the only CLJ-endorsed reference...
1
by: Peter Michaux | last post by:
Hi, It seems there is a long standing belief that in IE does not pass the event object to the handler functions attached with attachevent() to a DOM element. Coincidently, I was confused about a...
14
by: Peter Michaux | last post by:
Hi, For section 3.1 it might be worth noting that the fourth edition of Flanagan's JavaScript is out of print but a fifth edition is available. http://jibbering.com/faq/#FAQ3_1 I think it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.