var a= function (){var bb = 12; this.aa ="xxx"};
a.aa="www";
a.prototype.cc="eee";
var b = new a;
for (var i in b){
console.log(b[i]);
}
console.log (b)
console.log(b.aa)
console.log(b.bb)

  

xxx 
eee 
a {aa: "xxx", cc: "eee"} 
xxx
undefined

 总结,构造函数,传递给实例的是this和prototype定义,其他自身的定义的变量,没用传递给实例
 
var a= function (){var bb = 12; this.aa ="xxx"};
a.aa="www";
 a.prototype = "eee";//1 或者“ss” new Number(1111) function(){this.cc="ddd"};
;

  如果将prototype 不赋值为object,而是赋值为原始值,prototype不会传递给实例

xxx 
a {aa: "xxx"} 
xxx 
undefined

var a= function (){var bb = 12; this.aa ="xxx"};
a.aa="www";
a.prototype = new Number(1111);
var b = new a;
for (var i in b){
console.log(b[i]);
}
console.log (b)
console.log(b.aa)
console.log(b.bb)  

xxx 
a {aa: "xxx"} 
xxx 
undefined

	var a= function (){var bb = 12; this.aa ="xxx"};
a.aa="www";
a.prototype = new String("11111");
var b = new a;
for (var i in b){
console.log(b[i]);
}
console.log (b)
console.log(b.aa)
console.log(b.bb)

  

xxx 
5undefined 
a {aa: "xxx", 0: "1", 1: "1", 2: "1", 3: "1", 4: "1"} 
xxx 
undefined

new String,相当于使用数组对象存储的,但是遍历不出来值。

var a= function (){var bb = 12; this.aa ="xxx"};
a.aa="www";
a.prototype = [1,2];
var b = new a;
for (var i in b){
console.log(b[i]);
}
console.log (b)
console.log(b.aa)
console.log(b.bb)

  

xxx 


[aa: "xxx", 0: 1, 1: 2] 
xxx 
undefined

prototype就是{},实例化的对象,key value形式的,其他的都不行,不做传递。

var a=[1,2,3];
for(var i in a){
console.log(typeof i);
console.log(a[i]); }

  

string 

string 

string

3

数组的下标和对象一样,都是stirng

 var a=[1,2,3];
for(var i in a){
console.log(typeof i);
console.log(a[i]); }
var b={0:a,1:b}
console.log(b[0])
console.log(b[1])

  

string 

string 

string 

[1, 2, 3]

undefined

这就是数组的基本方式,

在对象中,如果是数组方式当key,不能使用b.1或者b."1",会报语法错误,跟array保持一致了

b[0]===b["0"] 为ture

总结:

只有this,prototype的值传递给实例,其中prototype必须是key-value的形式才传递,就是实例化后的,

数组和object的关系就是都一致的。

关于构造函数什么值传递给他的实例,只有this和prototype的更多相关文章

  1. new 运算符创建一个用户定义的对象类型的实例或具有构造函数的内置对象的实例。

    new运算符 - JavaScript | MDN https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operator ...

  2. python接口测试:如何将A接口的返回值传递给B接口

    在编写接口测试脚本时,要考虑一个问题:参数值从哪里获取 一种方式是可以通过数据库来获取,但是通过这次接口测试,我发现读取数据库有一个缺点:速度慢 可能和我的sql写法有关,有些sql加的约束条件比较少 ...

  3. art.dialog.art 中,将子页面窗口中的值传递给父框架中

    artDialog.open.origin.document.getElementById('父元素ID').value=document.getElementById('子页面元素ID').valu ...

  4. Postman----登录接口返回的reponse中token值传递给其他接口的一个简单接口测试示例

    注: 在进行接口测试时,我们都需要使用登录,并且其他的接口都要在登录后进行,那么必不可少的会使用到将登录接口的reponse返回结果中的某些参数值需要进行返回,并传递给其他接口,这样才可以进行登录后的 ...

  5. Net设计模式实例之原型模式( Prototype Pattern)

    一.原型模式简介(Brief Introduction) 原型模式(Prototype Pattern):用原型实例指定创建对象的种类,并通过拷贝这些原型创建新的对象. Specify the kin ...

  6. Spring 学习指南 第三章 bean的配置 (未完结)

    第三章 bean 的配置 ​ 在本章中,我们将介绍以下内容: bean 定义的继承: 如何解决 bean 类的构造函数的参数: 如何配置原始类型 (如 int .float 等) .集合类型(如 ja ...

  7. JS学习:第一周——NO.3面向对象

    [面向对象基础知识] 封装:对于功能相同的代码,我们只需封装一次,以后再遇到类似的功能,只需调用即可,无需重写,避免大量冗余代码. 对象的特征:方法和属性: 面向对象的特点: 封装:低耦合高内聚: 继 ...

  8. js 中的原型prototype

    每次创建新函数,就会根据规则为该函数创建一个 prototype 属性,该属性是一个指向函数原型对象的指针.并且原型对象都默认拥有一个 constructor 属性,该属性是一个指向那个新建函数的指针 ...

  9. 进击JavaScript核心 --- (3)面向对象

    JS中的对象定义为:无序属性的结合,其属性可以包含基本值.对象或者函数   1.定义对象的方式   (1).Object构造函数 var student = new Object(); student ...

随机推荐

  1. Linux下cpu过高问题排查

    原文地址:https://blog.csdn.net/chenjunan888/article/details/80447800 在服务器报cpu过高时,可使用以下命令,快速导出堆栈信息,以方便查看具 ...

  2. RHEL 6.5----Nginx负载均衡

    实验环境 主机名 IP master 192.168.30.130 node-1 192.168.30.131 node-2 192.168.30.132 在master上安装 本次安装过程统一采用Y ...

  3. ES6初探——编译环境搭建

    不好意思我又要来写操作文档了,看起来更像wiki的博客(如果你想深入学习,请阅读文末列的参考资料).本文将示例如何把ES6编译成ES5. 首先,你要自行查阅什么是ES6,和ES5.javascript ...

  4. npm安装使用及vue脚手架安装

    公司在前端用vue开发项目,那就学习下啦,第一步,在安装vue-devtools过程中,npm作为官方manual installtion方式,肯定必不可少. NPM是随同NodeJS一起安装的包管理 ...

  5. 第一周作业javaee strainmap

  6. 闲着蛋疼没事干,写个Mac端的Kcptun Client管理器

    原理: 执行一行脚本 输入服务器地址,端口,密码等做了图形化编辑 可以控制Kcptun是否正在运行 App已上传github https://github.com/nicky2k8/KcptunCli ...

  7. flask 项目部分业务逻辑

    @passport_blu.route('/image_code') def get_image_code(): """ 生成图片验证码并返回 1. 取到参数 2. 判断 ...

  8. 【整理】 vue-cli 打包后显示favicon.ico小图标

    vue-cli 打包后显示favicon.ico小图标 https://www.cnblogs.com/mmzuo-798/p/9285013.html

  9. QT+ 状态栏+核心控件+浮动窗口

    #include "mainwindow.h" #include <QStatusBar> #include <QLabel> #include<QT ...

  10. 从零开始--系统深入学习Android

    http://www.cnblogs.com/tianjian/category/354587.html