用法:with (<对象>) <语句>;
The with() statement in JavaScript is identical to the With statement found in Visual Basic. Using with(), you can reduce object references and make your code more readable. Surprisingly, it is possible to have nested with() statements. For example, this code:
function foo(){
var x = document.forms[0].elements[0].value;
var y = document.forms[0].elements[1].value;
var z = document.forms[0].elements[2].options[document.forms[0].elements[2].selectedIndex].text;
}
could be rewritten as:
function foo(){
with(document.forms[0]){
var x = elements[0].value;
var y = elements[1].value;
with(elements[2]){
var z = options[selectedIndex].text
}
}
}
another example:
x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10);
y = Math.tan(14 * Math.E);
could be rewritten as:
with (Math) {
x = cos(3 * PI) + sin(LN10);
y = tan(14 * E);
}
JavaScript 有许多保留关键字,这些关键字可分为三种类型:JavaScript 保留关键字、将来的保留字和应避免的单词。
JavaScript 关键字
break
continue
true
false
for
while
if
else
void
new
delete
function
return
typeof
with
in
this
var
null
JavaScript 将来的关键字
case
debugger
export
super
catch
default
extends
switch
class
do
finally
throw
const
enum
import
try
要避免的单词是那些已经用作 JavaScript 的内部对象或函数的名称的字。例如 string 或 parseInt 等单词均属此列。
使用前两类中的任何关键字都会在第一次载入脚本时导致编译错误。
如果使用第三类中的保留字,则当您试图在同一个脚本中使用其作为变量,同时又要使用其原来的实体时,可能会出现奇怪的问题。例如,下面的脚本不会完全按照您所想的那样被执行:
var String;
var text = new String(“This is a string object”);
在本例中,您将得到一个错误,称 String 不是一个对象。不过很多使用已有标识符的例子并没有这么明显。
this
用来返回“当前”对象。但在不同的场景,this 代表的对象并不相同。
如果在 JavaScript 的“主程序”中(不在任何 function 中,不在任何事件处理程序中)使用 this,它就代表 window 对象;
如果在 with 语句块中使用 this,它就代表 with 所指定的对象;
如果在事件处理程序中使用 this,它就代表发生事件的对象。
lang
用来指定代码语言,目前支持的程序设计语言有:
• actionscript
• cpp
• css
• diff
• dtd
• html
• java
• javascript
• mysql
• perl
• php
• python
• ruby
• sql
• xml
linenum
用来指定是否显示行号;
<coolcode lang=”程序设计语言” linenum=”off”>
代码
</coolcode>
download
用来指定是否可以下载代码文件:
<coolcode lang=”程序设计语言” download=”文件名.扩展名”>
代码
</coolcode>
任务栏里的显示桌面丢失了怎么办?
(1)记事本新建输入:
[Shell]
Command=2
IconFile=explorer.exe,3
[Taskbar]
Command=ToggleDesktop
(2)保存为 显示桌面.scf;
(3)拖到快速启动。
问题解决!
TEXTAREA的必选属性:cols、rows
TEXTAREA的可选属性:disabled、name、readonly
TEXTAREA的标准属性:id、class、style
TEXTAREA是没有maxlength属性的,因此,要控制textarea内的最大输入时需要选择另外的途径。
http://www.w3schools.com/tags/tag_textarea.asp
http://www.laoweng.com/article.asp?id=173
antlr.jar
ANTLR(ANother Tool for Language Recognition)它是这样的一种工具,它可以接受词文法语言描述,并能产生识别这些语言的语句的程序。作为翻译程序的一部分,你可以使用简单的操作符和动作来参数化你的文法,使之告诉ANTLR怎样去创建抽象语法树(AST)和怎样产生输出。ANTLR知道怎样去生成识别程序,语言包括Java,C++,C#.
主页:http://www.antlr.org/
参考链接:
http://www.blogjava.net/calvin/archive/2005/08/29/11463.html
http://www.blogjava.net/huanzhugege/archive/2007/10/29/156798.html
cglib.jar
CGLIB库,Hibernate用它来实现PO字节码的动态生成。
commons-collections.jar:
Apache Commons包中的一个,包含了一些Apache开发的集合类,功能比java.util.*强大。必须使用的jar包。
commons-beanutils.jar
Apache Commons包中的一个,包含了一些Bean工具类。必须使用的jar包。
commons-lang.jar
Apache Commons包中的一个,包含了一些数据类型工具类,是java.lang.*的扩展。必须使用的jar包。
commons-logging.jar
Apache Commons包中的一个,包含了日志功能,必须使用的jar包。这个包本身包含了一个Simple Logger,但是功能很弱。在运行的时候它会先在CLASSPATH找log4j,如果有,就使用log4j,如果没有,就找JDK1.4带的 java.util.logging,如果也找不到就用Simple Logger。commons-logging.jar的出现是一个历史的的遗留的遗憾,当初Apache极力游说Sun把log4j加入JDK1.4,然而JDK1.4项目小组已经接近发布JDK1.4产品的时间了,因此拒绝了Apache的要求,使用自己的java.util.logging,这个包的功能比log4j差的很远,性能也一般。
后来Apache就开发出来了commons-logging.jar用来兼容两个 logger。因此用commons-logging.jar写的log程序,底层的Logger是可以切换的,你可以选择log4j, java.util.logging或者它自带的Simple Logger。不过我仍然强烈建议使用log4j,因为log4j性能很高,log输出信息时间几乎等于System.out,而处理一条log平均只需要5us。你可以在Hibernate的src目录下找到Hibernate已经为你准备好了的log4j的配置文件,你只需要到Apache 网站去下载log4j就可以了。commons-logging.jar也是必须的jar包。
c3p0.jar
C3PO是一个数据库连接池,Hibernate可以配置为使用C3PO连接池。如果你准备用这个连接池,就需要这个jar包。
proxool.jar
也是一个连接池,同上。
commons-pool.jar、commons-dbcp.jar
DBCP数据库连接池,Apache的Jakarta组织开发的,Tomcat4的连接池也是DBCP。
connector.jar
JCA 规范,如果你在App Server上把Hibernate配置为Connector的话,就需要这个jar。不过实际上一般App Server肯定会带上这个包,所以实际上是多余的包。
dom4j.jar
解析XML文档。
参考文档:http://www.ibm.com/developerworks/cn/xml/x-dom4j.html
odmg.jar
ODMG是一个ORM的规范,Hibernate实现了ODMG规范,这是一个核心的库,必须使用的jar包。
jaas.jar
JAAS是用来进行权限验证的,已经包含在JDK1.4里面了。所以实际上是多余的包。
jcs.jar
如果你准备在Hibernate中使用JCS的话,那么必须包括它,否则就不用。
jdbc2_0-stdext.jar
JDBC2.0的扩展包,一般来说数据库连接池会用上它。不过App Server都会带上,所以也是多余的。
jta.jar
JTA规范,当Hibernate使用JTA的时候需要,不过App Server都会带上,所以也是多余的。
junit.jar
Junit包,当你运行Hibernate自带的测试代码的时候需要,否则就不用。
xalan.jar, xerces.jar, xml-apis.jar
Xerces是XML解析器,Xalan是格式化器,xml-apis实际上是JAXP。一般App Server都会带上,JDK1.4也包含了解析器,不过不是Xerces,是Crimson,效率比较差,不过Hibernate用XML只不过是读取配置文件,性能没什么紧要的,所以也是多余的。
final
final means, this value won’t be changed here after.
final is one of the most under-used features of Java. Whenever you compute a value and you know it will never be changed subsequently put a final on it. Why?
• final lets other programmers (or you reviewing your code years later) know they don’t have to worry about the value being changed anywhere else.
• final warns won’t let you or someone else inadvertently change the value somewhere else in the code, often by setting it to null. final helps prevent or flush out bugs. You can always remove it later.
• final helps the compiler generate faster code.
The term final is used in a number of contexts. static final variables are close to constants in other languages. final classes may not be subclassed. final methods may not be overridden. On methods private implies final, but on variables does not. Marking things final has two purposes: efficiency and safety. The compiler can perform various optimisations knowing the value cannot change. Hotspot and optimising compilers now do this anyway, whether or not you declare methods final, so using final purely for efficiency is no longer recommended. The compiler can also check to ensure you do not inadvertently attempt to change the value after computing its value once where it is defined.
A little known feature of Java is blank finals. You can declare member variables final, but not declare a value. This forces all constructors to initialise the blank final variables.
You can have both final instance and final static variables. final statics are more common. When you know the value of a constant at compile time you might as well make it static. It takes up less room, just one copy per class instead of one copy per object. It is also faster to access a static constant than an instance constant. However, if you don’t know the value of the constant until instantiation time, you have to make it an instance constant.
If you have a final reference to an object or array, it does not stop you from changing the fields in the object or elements of the array. It just stops you from pointing that variable to a different object or array. If you want to protect the object, you must make it immutable.
from:http://mindprod.com/jgloss/final.html
对final总结很全面的一片文章:http://renaud.waldura.com/doc/java/final-keyword.shtml
this是当前对象的引用,主要有如下四个作用:
1.用于返回类对象本身。
2.在构造方法内调用其他构造方法。
3.在方法内部调用类对象中的其他方法。
4.标识类成员变量。
http://mindprod.com/jgloss/this.html
super关键字有两个作用:
1、调用超类方法
2、调用超类的构造器
Accessing Superclass Members
If your method overrides one of its superclass’s methods, you can invoke the overridden method through the use of the keyword super. You can also use super to refer to a hidden field (although hiding fields is discouraged). Consider this class, Superclass:
public class Superclass {
public void printMethod() {
System.out.println(“Printed in Superclass.”);
}
}
Here is a subclass, called Subclass, that overrides printMethod():
public class Subclass extends Superclass {
public void printMethod() { //overrides printMethod in Superclass
super.printMethod();
System.out.println(“Printed in Subclass”);
}
public static void main(String[] args) {
Subclass s = new Subclass();
s.printMethod();
}
}
Within Subclass, the simple name printMethod() refers to the one declared in Subclass, which overrides the one in Superclass. So, to refer to printMethod() inherited from Superclass, Subclass must use a qualified name, using super as shown. Compiling and executing Subclass prints the following:
Printed in Superclass.
Printed in Subclass
Subclass Constructors
The following example illustrates how to use the super keyword to invoke a superclass’s constructor. Recall from the Bicycle example that MountainBike is a subclass of Bicycle. Here is the MountainBike (subclass) constructor that calls the superclass constructor and then adds initialization code of its own:
public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
super(startCadence, startSpeed, startGear);
seatHeight = startHeight;
}
Invocation of a superclass constructor must be the first line in the subclass constructor.
The syntax for calling a superclass constructor is
super();
–or–
super(parameter list);
With super(), the superclass no-argument constructor is called. With super(parameter list), the superclass constructor with a matching parameter list is called.
——————————————————————————–
Note: If a constructor does not explicitly invoke a superclass constructor, the Java compiler automatically inserts a call to the no-argument constructor of the superclass. If the super class does not have a no-argument constructor, you will get a compile-time error. Object does have such a constructor, so if Object is the only superclass, there is no problem.
——————————————————————————–
If a subclass constructor invokes a constructor of its superclass, either explicitly or implicitly, you might think that there will be a whole chain of constructors called, all the way back to the constructor of Object. In fact, this is the case. It is called constructor chaining, and you need to be aware of it when there is a long line of class descent.
from:http://java.sun.com/docs/books/tutorial/java/IandI/super.html