Part One:
1. Two steps to create custom object
1) Use constructor to create object type/class
2) Create object instance
Cause there is no concept of Class in JavaScript compared with that in java.
2. Attributes can be defined in object dynamically.
1) Create function name for this object in constructor
2) Create function that describes this function
3. Example of Constructor
1) Attributes Assignment
function member(name, gender) { this.name = name; this.gender = gender; } var m1 = new member("Davy", "Male"); var m2 = new member("Jones", "Female"); var m3 = new member("Calyp", "Female"); with(document) { // The way to gain access to the properties inside this object write(m1.name + " : " + m1.gender + "</br>"); write(m2.name + " : " + m2.gender + "</br>"); write(m3.name + " : " + m3.gender + "</br>"); }
2) Functions Assignment
function member(name, gender) { // assign properties this.name = name; this.gender = gender; // assign functions this.display = display; } function display() { var str = this.name + " : " + this.gender; // key word "this" represents the object who called this method not like that in Java document.write(str + "<br/>"); } var m1 = new member("Davy", "Male"); var m2 = new member("Jones", "Female"); var m3 = new member("Calyp", "Female"); m1.display(); m2.display(); m3.display();
Part Two:
1. Event call/response process
Browser response to a specific event and realize interactive operation process.
That is we bind a function/method to a specific event. The time this event happens, the function is called.
Example as below:
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <script type="text/javascript"> function mouseoverCallback(object) { object.color = "blue"; } function mouseoutCallback(object) { object.color = "black"; } </script> </head> <body> <font style="cursor:hand" onclick="window.location.href='http://www.google.com'" onmouseover="mouseoverCallback(this);" onmouseout="mouseoutCallback(this);">Welcome</font> </body> </html>
Part Three:
1. Timer ---> Two kinds of timer "setTimeout()" and "setInterval()"
========================setTimeout()====================
Execute a segment of code/function once after a specific time.
setTimeout();
Syntax: [timerObjectName=] setTimeout("expression", millseconds);
Execute expression once.
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <script type="text/javascript"> function count() { setTimeout("alert('Welcome');", 4000); } </script> </head> <body> <input type="button" value="TimerStart" onclick="count();"/> </body> </html>
========================setInterval()====================
Execute a segment of code/function repeatly after a specific time.
setTimeout();
clearInterval();
Syntax: [timerObjectName=] setTimeout("expression", millseconds);
Execute expression every millseconds.
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <script type="text/javascript"> var countTimer; function count() { countTimer = setInterval("alert('Welcome');", 4000); } function stop() { clearInterval(countTimer); } </script> </head> <body> <input type="button" value="TimerStart" onclick="count();"/> <input type="button" value="TimerStop" onclick="stop();"/> </body> </html>
========================A simple timer example====================
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <html> <head> <title>My JSP 'index.jsp' starting page</title> <script type="text/javascript"> var countTimer; var countNumber = 0; function count() { countTimer = setInterval("numberIncrease();", 1000); } function numberIncrease() { countNumber ++; document.getElementById("count").innerHTML = countNumber; } function stop() { clearInterval(countTimer); } </script> </head> <body> <font color="red" id="count">0</font><br/> <input type="button" value="TimerStart" onclick="count();"/> <input type="button" value="TimerStop" onclick="stop();"/> </body> </html>
相关推荐
11: References & the Copy-Constructor 12: Operator Overloading 13: Dynamic Object Creation 14: Inheritance & Composition 15: Polymorphism & Virtual Functions 16: Introduction to Templates A: Coding ...
“base constructor”<<std::endl; func1(); std::cout<<std::endl; } virtual ~base() { std::cout<<std::endl; std::cout<<“base distructor”<<std::endl; func
constructor是什么 简单的理解,...Object.constructor);//Function alert(Function.constructor);//Function 对于foo.constructor为Foo,我想应该很好理解,因为foo的构造函数为Foo。对于Foo、Object、Fun
JSP辅助编程工具(不太成熟)可以从SQL Script中(MySQL)提取关键字后,一步转换成...constructor:setter & getter;相应的add***();del***();mod***()函数作用:Sql只要符合要求的格式即可,方便jsp+javabean代码的编写
深化浅析JavaScript中的constructor_.docx
JS:typeof instanceof constructor prototype区别
wordpress主题WordPress主题:Constructor本资源系百度网盘分享地址
javascript设计模式Constructor(构造器)模式.docx
与PARCEL一起运行'npm run build''npm run serve'
constructor 属性返回对创建此对象的数组函数的引用。本文给大家介绍JavaScript中的constructor ,需要的朋友参考下吧
JavaScript Boolean.constructor()方法返回一个引用到创建实例的原型布尔函数。 语法 boolean.constructor() 返回值: NA 下面是参数的详细信息: 返回创建此对象的实例。 例子: <html> <head> <...
JavaScript的constructor属性[文].pdf
b.constructor==BB.prototype.constructor) //true 这里的“有了”的执行过程是先查看b有没有此属性让后去查看prototype里的属性值,不是简单的A=B:如添加:b.constructor=”ccc”; 执行:alert(b.constructor=...
第一个阶段: 代码如下: function A(){ this.funB = function(){ alert(‘A:funB’)... sub.prototype.constructor = sub; } extend(B,A); var b = new B(); b.funA(); // out ‘A:funA’ b.fun
bfs.cpp:11:15: error: expected constructor, destructor, or type conversion before ‘(’ token __declspec(dllexport) windows到linux的转换: windows下: #include #include #include #include using ...
TabPanel Constructor 提供了在 MATLAB 中创建 tabpanels 的最简单方法! - 无需编程! - 可以使用 GUIDE 轻松编辑所有标签面板! - 支持所有 MATLAB UI 控件。 - 结果是原始的 FIG 文件和随附的 M 文件,该文件...
public constructor() { super(); //字典使用对象作为key引用存储数据.对象作为key实际上需要进行遍历索引,所以在同一个字典中尽量不要添加过多的key会影响性能. var dic: Dictionary = new Dictionary(); var...
ubuntu 脱坑 & 日常constructor 属性prototype 属性ES6 class变量值类型React 渲染&优化MeteorRocketChat API目录结构meteor 路由[meteor 模板,解释](#meteor-模板解释)Collection 数据集合Methods RPC 协议实现方法...
// Private constructor because singleton! // Functions CString GetTime(); // Variables static std::auto_ptr<CLog> sm_inst; CStdioFile * m_pLogFile; bool m_bEnableTimestamp; };
对象的constructor属性用于返回创建该对象的函数,也就是我们常说的构造函数,除了创建对象,构造函数(constructor) 还做了另一件有用的事情—自动为创建的新对象设置了原型对象(prototype object)