对象

您所在的位置:网站首页 bool类型函数 对象

对象

2023-03-20 02:14| 来源: 网络整理| 查看: 265

构造函数及实例化原理包装类

构造函数及实例化原理function Car() { // this = { color: color, brand:brand // } this.color = 'red'; this.brand = 'brand'; // return this;}Car(); // 执行时产生AO,AO里面保存了this,指向windowvar car = new Car(); //---> 返回this // 实例化后this指向当前保存的对象,不实例化指向window// 实例时相当于普通函数被执行时,此时Car的AO// 可以想成new 把this造出来GO = { Car: (function), car1: { color: color, brand:brand }}AO = { this: { color: color, brand:brand }}function Car(color, brand) { var me = {}; me.color = color; me.brand = brand; return me; //me = { // color: color, // brand: brand // }}var car = Car('red','Mazda');function Car() { this.color = 'red'; this.brand = 'brand'; // 引用值:{} [] function return {} // return 引用值,返回引用值,而reutrn基本数据类型没用 // return this;}var car = new Car(); // {}

包装类// 原始值并没有自己的方法和属性var a = 1; // 原始值var b = new Number(a); // 实例化对象,可设置属性方法 数字对象// 经过包装后再参与运算又返回原始值var d = b + 1; // 2// new Number new String new Boolean// JS包装类var a = 123; // 原始值没有方法和属性a.len = 3;// new Number(123).len = 3; delete 赋值但没地方保存所以删除lenconsole.log(a.len); // undefined var str = 'abc'; // 包装类console.log(str.length); // 3// new String(str).lengthvar a = new Number(123); // 原始值 -> 数字a.len = 3console.log(a.len); // 3// length// 数组的截断var arr = [1,2,3,4,5];arr.length = 2;console.log(arr); // [1,2]var str = 'abc';str.length = 1; // new String(str).length = 1 deleteconsole.log(str); // 3// 题目一:var name = 'languiji';name += 10; // 'languiji10'var type = typeof(name); // 'string'if(type.length === 6){ // true type.text = 'string'; // new String(type).text = 'string' delete}console.log(type.text); // undefined// 题目二:function Test(a,b,c){ var d = 1; this.a = a; this.b = b; this.c = c; function f(){ d++; console.log(d); } this.g = f; // return this; -> 闭包}var test1 = new Test();test1.g(); // 2test1.g(); // 3var test2 = new Test();test2.g(); // 2// 题目三:var x = 1, y = z = 0;function add(n) { return n = n + 1;}y = add(x);function add(n){ return n = n + 3;}z = add(x);console.log(x,y,z) // 1,4,4GO = { x: 1, y: 0, z: 0, add: function(n){return n = n+1}; ->function(n){return n = n+3};}题目四:function foo1(x){ console.log(arguments); return x;}foo(1,2,3,4,5); // 1,2,3,4,5function foo2(x){ console.log(arguments); return x;}(1,2,3,4,5); // 不报错,不执行(function foo3(x){ console.log(arguments); return x;})(1,2,3,4,5); // 1,2,3,4,5题目五:function b(x,y,a){ a = 10; console.log(arguments[2]); // arguments[2]实参 映射关系 arguments[2] = 10; console.log(a); // 10}b(1,2,3); // 10

ASCII码 表1 0-127 表2 128 255 1个字节 byte

UNICODE码 涵盖ASCII码 0-255占一个字节 255位以后2个字节



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3