js new操作符
来源:互联网 发布:2016淘宝女装销量前十 编辑:程序博客网 时间:2024/05/17 03:18
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Insert title here</title>
- </head>
- <body>
- <script type="text/javascript">
- /*没有返回值
- function Test1(str) {
- this.a = str;
- }
- //new
- var myTest1 = new Test1('myTest1');
- alert(myTest1);//object Object
- //no new
- var myTest1 = Test1('myTest1');
- alert(myTest1);//undefined
- */
- /*有返回值
- function Test2(str) {
- this.a = str;
- return this.a;
- }
- //new
- var myTest2 = new Test2('myTest2');
- alert(myTest2);//object Object myTest2.a就是myTest2
- //no new
- var myTest2 = Test2('myTest2');
- alert(myTest2);//myTest2
- */
- /*返回值为new对象
- function Test3(str) {
- this.a = str;
- return new String(this.a);
- }
- var myTest3 = new Test3('myTest3');
- alert(myTest3);//String myTest3
- */
- /* new this
- function Test4(str) {
- this.a = str;
- }
- //对象的get_string方法
- Test4.prototype.get_string = function() {
- return this.a;//this指这个新对象 this.a 新对象的a属性值
- }
- var myTest4 = new Test4('myTest4');
- alert(myTest4.get_string());//myTest4
- */
- /*js 伪继承 伪类
- function Test5(str) {
- this.a = str;
- }
- Test5.prototype.get_Test5String = function() {
- return this.a;
- }
- var myTest5 = new Test5('myTest5');
- //alert(myTest5.get_Test5String());
- function Test6(str) {
- this.b = str;
- }
- Test6.prototype = new Test5('myTest5');//必须放在get_Test6String方法前 不然就冲掉了
- Test6.prototype.get_Test6String = function() {
- return this.b;
- }
- var myTest6 = new Test6('myTest6');
- alert(myTest6.get_Test6String());//myTest6
- alert(myTest6.get_Test5String());//myTest5
- */
- </script>
- </body>
- </html>
0 0
- js new操作符
- [JS] new操作符
- JS new 操作符
- js--new操作符
- js new操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS 中 new 操作符
- JS中的new操作符简单理解
- 分中心重新生成对账文件
- 设计模式-代理模式
- PHP数组FOREACH逆序输出,PHP数组倒序
- android studio中运行项目出现的坑
- Linux相关命令
- js new操作符
- 1
- PHP大数据之加减乘除
- LINQ 简介
- jpa一些查询方法
- Android开发中逐步取代MVC的MVP架构知多少?
- Phone List POJ3630
- STL中坑爹的max函数
- Cocos2d-x 3.x 图形学渲染系列三十