== VS ===(JavaScript: The Definitive Guide学习摘要5)

5.4.1. Equality (==) and Identity (===)
The == and === operators check whether two values are the same, using two
different definitions of sameness. Both operators accept operands of any type,
and both return true if their operands are the same and false if they are
different. The === operator is known as the identity operator, and it checks
whether its two operands are “identical” using a strict definition of
sameness. The == operator is known as the equality operator; it checks whether
its two operands are “equal” using a more relaxed definition of sameness that
allows type conversions.

The following rules determine whether two values are identical according to
the === operator:

  • If the two values have different types, they are not identical.

  • If both values are numbers and have the same value, they are identical, unless either or both values are NaN , in which case they are not identical. The NaN value is never identical to any other value, including itself! To check whether a value is NaN , use the global isNaN( ) function.

  • If both values are strings and contain exactly the same characters in the same positions, they are identical. If the strings differ in length or content, they are not identical. Note that in some cases, the Unicode standard allows more than one way to encode the same string. For efficiency, however, JavaScript’s string comparison compares strictly on a character-by-character basis, and it assumes that all strings have been converted to a “normalized form” before they are compared. See the String.localeCompare( ) reference page in Part III for another way to compare strings.

  • If both values are the boolean value true or both are the boolean value false , they are identical.

  • If both values refer to the same object, array, or function, they are identical. If they refer to different objects (or arrays or functions) they are not identical, even if both objects have identical properties or both arrays have identical elements.

  • If both values are null or both values are undefined , they are identical.

The following rules determine whether two values are equal according to the == operator:

  • If the two values have the same type, test them for identity. If the values are identical, they are equal; if they are not identical, they are not equal.

  • If the two values do not have the same type, they may still be equal. Use the following rules and type conversions to check for equality:

    • If one value is null and the other is undefined , they are equal.

    • If one value is a number and the other is a string, convert the string to a number and try the comparison again, using the converted value.

    • If either value is TRue , convert it to 1 and try the comparison again. If either value is false , convert it to 0 and try the comparison again.

    • If one value is an object and the other is a number or string, convert the object to a primitive and try the comparison again. An object is converted to a primitive value by either its toString( ) method or its valueOf( ) method. The built-in classes of core JavaScript attempt valueOf( ) conversion before toString( ) conversion, except for the Date class, which performs toString( ) conversion. Objects that are not part of core JavaScript may convert themselves to primitive values in an implementation-defined way.

    • Any other combinations of values are not equal.

值传递 VS 引用传递(JavaScript: The Definitive Guide学习摘要4)

3.15. By Value Versus by Reference
In JavaScript, as in all programming languages, you can manipulate a data
value in three important ways.First, you can copy it. For example, you might
assign it to a new variable. Second, you can pass it as an argument to a
function or method. Third, you can compare it with another value to see
whether the two values are equal. To understand any programming language, you
must understand how these three operations are performed in that language.

There are two fundamentally distinct ways to manipulate data values. These
techniques are called by value and by reference. When a datum is manipulated
by value, it is the value of the datum that matters. In an assignment, a copy
of the actual value is made, and that copy is stored in a variable, object
property, or array element; the copy and the original are two totally
independent values that are stored separately. When a datum is passed by value
to a function, a copy of the datum is passed to the function; if the function
modifies the value, the change affects only the function’s copy of the datumit
does not affect the original datum. Finally, when a datum is compared by value
to another datum, the two distinct pieces of data must represent exactly the
same value (which usually means that a byte-by-byte comparison finds them to
be equal).

The other way to manipulate a value is by reference. With this technique,
there is only one actual copy of the value; references to that value are
manipulated. If a value is manipulated by reference, variables do not hold
that value directly; they hold only references to it. It is these references
that are copied, passed, and compared. So, in an assignment made by reference,
it is the reference to the value that is assigned, not a copy of the value and
not the value itself. After the assignment, the new variable refers to the
same value that the original variable refers to. Both references are equally
valid, and both can be used to manipulate the value; if the value is changed
through one reference, that change also appears through the original
reference. The situation is similar when a value is passed to a function by
reference. A reference to the value is passed to the function, and the
function can use that reference to modify the value itself; any such
modifications are visible outside the function. Finally, when a value is
compared to another by reference, the two references are compared to see if
they refer to the same unique copy of a value; references to two distinct
values that happen to be equivalent (i.e., consist of the same bytes) are not
treated as equal.

These are two very different ways of manipulating values, and they have
important implications that you should understand. Table 3-4 summarizes these
implications. This discussion of manipulating data by value and by reference
has been a general one, but the distinctions apply to all programming
languages. The sections that follow explain how these distinctions apply
specifically to JavaScript; they discuss which datatypes are manipulated by
value and which are manipulated by reference.

Table 3-4. By value versus by reference

By value

By reference

Copy

The value is actually copied; there are two distinct, independent copies.

Only a reference to the value is copied. If the value is modified through the
new reference, that change is also visible through the original reference.

Pass

A distinct copy of the value is passed to the function; changes to it have no
effect outside the function.

A reference to the value is passed to the function. If the function modifies
the value through the passed reference, the modification is visible outside
the function.

Compare

Two distinct values are compared (often byte by byte) to see if they are the
same value.

Two references are compared to see if they refer to the same value. Two
references to distinct values are not equal, even if the two values consist of
the same bytes.

By Value Versus by Reference: Summary

Table 3-5 summarizes the way that the various JavaScript types are
manipulated.

Table 3-5. Datatype manipulation in JavaScript

Type

Copied by

Passed by

Compared by

number

Value

Value

Value

boolean

Value

Value

Value

string

Immutable

Immutable

Value

object

Reference

Reference

Reference

类型转换总结(JavaScript: The Definitive Guide学习摘要3)

Section 3.12. Type Conversion Summary

|

—|—

Value

|

Context in which value is used

—|—

|

String

|

Number

|

Boolean

|

Object

3.12. Type Conversion Summary

As each datatype has been described in the previous sections, I’ve discussed
how values of each type convert into values of other types. The basic rule is
that when a value of one type is used in a context that requires a value of
some other type, JavaScript automatically attempts to convert the value as
needed. So, for example, if a number is used in a Boolean context, it is
converted to a boolean. If an object is used in a string context, it is
converted to a string. If a string is used in a numeric context, JavaScript
attempts to convert it to a number. Table 3-3 summarizes each of these
conversions and shows the conversion that is performed when a particular type
of value is used in a particular context.

Table 3-3. Automatic datatype conversions

Undefined value

|

"undefined"

|

NaN

|

false

|

Error

null

|

"null"

|

0

|

false

|

Error

Nonempty string

|

As is

|

Numeric value of string or NaN

|

TRue

|

String object

Empty string

|

As is

|

0

|

false

|

String object

0

|

"0"

|

As is

|

false

|

Number object

NaN

|

"NaN"

|

As is

|

false

|

Number object

Infinity

|

"Infinity"

|

As is

|

true

|

Number object

Negative infinity

|

"-Infinity"

|

As is

|

TRue

|

Number object

Any other number

|

String value of number

|

As is

|

true

|

Number object

true

|

"true"

|

1

|

As is

|

Boolean object

false

|

"false"

|

0

|

As is

|

Boolean object

Object

|

toString( )

|

valueOf( ) , toString( ) , or NaN

|

true

|

As is

|
—|—

Literals VS Identifiers(JavaScript: The Definitive Guide学习摘要2)

2.6. Literals

A literal is a _data value _ that appears directly in a program. The
following are all literals:

12 // The number twelve
1.2 // The number one point two
“hello world” // A string of text
‘Hi’ // Another string
true // A Boolean value
false // The other Boolean value
/javascript/gi // A “regular expression” literal (for pattern matching)
null // Absence of an object

2.7. Identifiers
An identifier is simply a name . In JavaScript, identifiers are used to
name variables and functions, and to provide labels for certain loops in
JavaScript code. The rules for legal identifier names are the same in
JavaScript as they are in Java and many other languages. The first character
must be a letter, an underscore (_), or a dollar sign ($).[*] Subsequent
characters can be a letter, a digit, an underscore, or a dollar sign. (Digits
are not allowed as the first character so that JavaScript can easily
distinguish identifiers from numbers.) These are all legal identifiers:

i
my_variable_name
v13
_dummy
$str

什么是JavaScript(JavaScript: The Definitive Guide学习摘要1)

1.1. What Is JavaScript?
JavaScript is the subject of a fair bit of misinformation and confusion.
Before proceeding any further, it is important to debunk two common and
persistent myths about the language.

1.1.1. JavaScript Is Not Java
One of the most common misconceptions about JavaScript is that it is a
simplified version of Java, the programming language from Sun Microsystems.
Other than an incomplete syntactic resemblance and the fact that both Java and
JavaScript can provide executable content in web browsers, the two languages
are entirely unrelated. The similarity of names is purely a marketing ploy by
Netscape and Sun (the language was originally called LiveScript; its name was
changed to JavaScript at the last minute). However, JavaScript can, in fact,
script Java (see Chapters 12 and 23).

1.1.2. JavaScript Is Not Simple
Because JavaScript is interpreted instead of compiled, it is often considered
a scripting language instead of a true programming language. The implication
is that scripting languages are simpler and that they are programming
languages for nonprogrammers. The fact that JavaScript is loosely typed does
make it somewhat more forgiving for unsophisticated programmers. And many web
designers have been able to use JavaScript for limited, cookbook-style
programming tasks.

Beneath its thin veneer of simplicity, however, JavaScript is a full-featured
programming language, as complex as any and more complex than some.
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.
This book documents JavaScript comprehensively so that you can develop a
sophisticated understanding. If you are used to cookbook-style JavaScript
tutorials, you may be surprised at the depth and detail of the chapters ahead.

MySQL数据库的恢复问题

1.要恢复MySQL数据库的话,先要看你自己的table是建立在什么样的引擎上的。

使用show engines命令可以查看自己是MySQL支持什么引擎,下表是我的结果。

mysql> show engines;
+————+———+—————————————————————-+
| Engine | Support | Comment |
+————+———+—————————————————————-+
| MyISAM | YES | Default engine as of MySQL 3.23 with great performance |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables |
| HEAP | YES | Alias for MEMORY |
| MERGE | YES | Collection of identical MyISAM tables |
| MRG_MYISAM | YES | Alias for MERGE |
| ISAM | NO | Obsolete storage engine, now replaced by MyISAM |
| MRG_ISAM | NO | Obsolete storage engine, now replaced by MERGE |
| InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign
keys |
| INNOBASE | YES | Alias for INNODB |
| BDB | YES | Supports transactions and page-level locking |
| BERKELEYDB | YES | Alias for BDB |
| NDBCLUSTER | NO | Clustered, fault-tolerant, memory-based tables |
| NDB | NO | Alias for NDBCLUSTER |
| EXAMPLE | NO | Example storage engine |
| ARCHIVE | YES | Archive storage engine |
| CSV | NO | CSV storage engine |
| FEDERATED | YES | Federated MySQL storage engine |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it
disappears) |
+————+———+—————————————————————-+

2.不同的引擎恢复方法不同,下面分别介绍;

MEMORY:不能备份,因为表中的所用内容都是放在内存中的,当MySQL服务重启后,所有的内容丢失;

MyISAM:可直接将数据库所在的目录copy/打包进行备份;

ARCHIVE:可直接将数据库所在的目录copy/打包进行备份;但是它只支持select和insert命令,不支持 auto inc,不能有索引和主键;

MERGE/MRG_MYISAM:可直接将数据库所在的目录copy/打包进行备份;只读的表;

参考:

mysql所支持的所有数据库引擎:
http://solutions.mysql.com/engines.html
介绍archive引擎的文章:
http://dev.mysql.com/tech-resources/articles/storage-engine.html
http://dev.mysql.com/doc/refman/5.1/en/archive-storage-engine.html
介绍merge引擎的文章:
http://dev.mysql.com/doc/refman/5.1/en/merge-storage-engine.html

3.InnoDB的问题

简单的说InnoDB不能通过直接copy数据库所在的目录来进行备份,所以数据库的引擎如果是它的话,

你最好经常使用mysqldump命令来备份你自己的数据库。

PS:关于InnoDB的备份的问题,我google了两天,没有完美的解决方案,有人说有一个 InnoDB Hot Backup

可以进行备份,我没有试过。

如果以上对你有帮助的话,请回复让我知道。

端口绑定异常

今天在启动我们的产品时,老是出以下异常:

Cannot assign requested address: JVM_Bind

原先我还以为是程序使用的端口被占用了呢,于是用:

netstat -a | findstr “2730”

查看了一下,但是没有找出来,说明端口没有被占用;

所以就想用没有可能java的serversocket异常退出后,

没有关掉自己使用过的端口,于是在google了一下,但是

大家都没有遇到过类似的现象,于是检查了一下自己的

配置,一看自己的IP地址配置错误。狂晕。一个小时啊,

白白的浪费了。

所以在开始工作之前,一定要先确认自己的工作环境是否正确。

也要充分理解各种配置文件参数的具体含义!!!

如何备份csdn的blog

担心csdn我的blog整没了,于是向找个东西将blog下载到本机。

于是BackStreet Browser出现了,它是我找了半天才找到的一个合适的工具,首先它是免费的,不会下载

不需要的网站,支持代理。

但是它的缺点是不能备份想校内那样的网站,因为它们需要认证,我看要真想备份的话,只能是自己写个脚本什么的了。

下载地址:

http://www.snapfiles.com/reviews/BackStreet_Browser/backstreet.html

PS: kao,就在刚才我的这篇文章提交失败,害的我还重写了一遍。

无语。。。

关于hibernate的两个问题

1.SQL VS HQL
The Hibernate SQLQuery bypasses the Hibernate Session cache and queries ONLY
against the
database. By the same token, HQL and the Hibernate Criteria queries check the
Session cache
before executing the query. If there are objects that the HQL query may
execute against
hibernate will flush the cache to the database.
Hibernate SQLQuery绕过Hibernate 会话的缓存,直接从数据库中查询;也就是说,HQL and
the Hibernate Criteria queries在执行前会先检查会话的缓存,如果缓存中存在该查询需要的
对象,hibernate会将它更新到数据库中去;

2.会话必须在一个线程使用,因为它不是线程安全的;
Sessions should be used by only one application thread at a time. This is a
common concern in web applications, which are multithreaded by their very
nature.

所以不要将在session1中取出来的东西,在session2中调用saveOrUpdate方法,会抛异常;

如果你必须要这样做的话,请使用save或者update方法,这样hibernate就不用通过判断来调用save或者update方法了。

http://i-proving.ca/space/Technologies/Hibernate/SQL+vs+HQL+with+the+Session+Cache
http://www.developer.com/open/article.php/10930_3559931_4

Java的一个错误提示

最近在写代码时,遇到一个错误提示,老是不知道为什么,于是google了一下,将结果写下来,供大家学习和交流。

错误提示:

No enclosing instance of type Foo is accessible. Must qualify the allocation
with an enclosing instance of type Foo (e.g. x.new A() where x is an instance
of Foo).

原因是:

if you try to instantiate an inner class without an instance of the outer
class.

在没有外部类对象时试图初始化一个内部类。

所以你应该先new一个外部类,然后通过它来new内部类

参见:

http://java.sun.com/docs/books/tutorial/java/javaOO/innerclasses.html

http://java.syntaxerrors.info/index.php?title=No_enclosing_instance_of_type_Foo_is_accessible._Must_qualify_the_allocation_with_an_enclosing_instance_of_type_Foo_(e.g._x.new_A()_where_x_is_an_instance_of_Foo).