当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript面象对象设计

Javascript
Add a Table to a Word Document
Add Formatted Text to a Word Document
用jscript实现新建word文档
用jscript实现新建和保存一个word文档
Open and Print a Word Document
Use Word to Search for Files
Convert Seconds To Hours
Sample script that deletes a SQL Server database
Sample script that displays all of the users in a given SQL Server DB
firefox中用javascript实现鼠标位置的定位
div+css实现鼠标放上去,背景跟图片都会变化。
Locate a File Using a File Open Dialog Box
Save a File Using a File Save Dialog Box
用jscript实现列出安装的软件列表
List the Stored Procedures in a SQL Server database
Display SQL Server Login Mode
Display SQL Server Version Information
List all the Databases on a SQL Server
用jscript启动sqlserver
Stop SQL Server

Javascript 中的 JavaScript面象对象设计


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 163 ::
收藏到网摘: n/a

学习js的高境界就是使用面向对象的方法,实现js的调用 新一篇: JavaScript中字符串相等比较
面象对象的应用是相当广泛的,在桌面编程中很早就出现了,应用比较成熟,象C++,Java,C#等。而在Web编程这一块,出现就要晚得多,以致于现在的Web开发很困难,当然也有Web开发牵涉的技术多的原因。近年来,面向对象逐渐在Web开发中被引入。很多大型的网站是采用PHP开发的,PHP 4中面向对象的还不是很完善,在PHP 5中有所改进。.Net也面向对象,但执行效率比不上PHP。
JavaScript在Web开发中用得也是相当多的,常用的表单验证很多是用它来完成的。JavaScript做为一门脚本语言,没有专门的IDE开发环境,也没有好的调试工具,发展是相当缓慢的,一直以来都没有得人们的关注。直到Ajax的出现,才给它带来了生机。也让人们真正看到了它与其它技术给合所带来的效果。
JavaScript是包含面象对象在里面的,只是在应用当中没有普及罢了。
看个简单的例子:
定义CTest类 // CTest.js
function CTest()
{
this.m_sStr = "";
this.Input = CTest_Input;
this.Output = CTest_Output;
function CTest_Input(str)
{
this.m_sStr = str;
}
function CTest_Output()
{
alert(this.m_sStr);
}
}
使用方法 <!-- CTest.html -->
<script type="text/javascript" src="CTest.js"></script>
<script type="text/javascript">
var g_CTest = g_CTest = new CTest();
g_CTest.Input("Hello! Welcome to my Blog!");
g_CTest.Output();
</script>
是不是很象C++,用起来是不是要方便多了。