<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
// var mrDeng = {
// name : "MrDeng",
// age : 40,
// sex : "male",
// health : 100,
// smoke : function () {
// console.log('I am smoking ! cool!!!')
// this.health --;
// },
// drink : function () {
// console.log('I am drink');
// this.health ++;
// }
// }
// mrDeng.wife = "xiaodeng";
// delete mrDeng.name;
// var deng = {
// prepareWife : "xiaodeng",
// name : "laodeng",
// sex : "male",
// gf : " xiaoliu",
// wife : "",
// divorce : function () {
// delete this.wife;
// this.wife = this.prepareWife;
// },
// getMarried : function () {
// this.wife = this.gf;
// },
// changeGf : function (someone) {
// this.gf = someone;
// }
// }
//对象的创建方法
//1.var obj = {} plainObject 对象字面量/对象直接量
//2.构造函数
// 1) 系统自带的构造函数 new Object() Array()
// 2) 自定义
// var obj = new Object();
// var obj = {};
// function Car(color) {
// this.color = color;
// this.name = "BWM";
// this.height = "1400";
// this.lang = "4900";
// this.weight = 1000;
// this.health = 100;
// this.run = function () {
// this.health --;//我的这个车的减减
// }
// }
// var car = new Car("red");
// var car1 = new Car("green");
// car.name = "qaq";
// car1.name = "qer";
// function Student(name,age,sex){
// // var this = {
// // name : "";
// // age :
// // }
// this.name = name;
// this.age = age;
// this.sex = sex;
// this.grade = 2017;
// //return this;
// }
// var student = new Student("deng",22,"男");
// function Person(name, height) {
// //var this = {};
// this.name = name;
// this.height = height;
// this.say = function () {
// console.log(this.say);
// }
// // return 123;
// //有new 就不能返回其他数值。。。
// //return this;
// }
// console.log(new Person("xiaowang",180).name);
// var person = new Person("qaq",123);
// function Person(name, height) {
// var that = {};
// that.name = name;
// that.height = height;
// return that;
// }
// var person = Person("xiaowang",180);
// var num = 123;
// var num1 = new Number(123);
// var str = "";
// var str1 = new String('abacdd');
// str1.a = 'bcd';
//包装类
// var num = 4;
// num.len = 3;
// //new Number(4).len = 3; delete
// //
// //new Nember(4).len 俩对象;
// console.log(num.len); //undefined
// var arr = [1,3,4,5,6,7];
// var str = "abcd";
// str.length = 2;
// //new String('abcd').length = 2 ; delete
// //
// //new String('abac').length
// console.log(str.length); //4
// console.log(str);//abcd
// var str = "abc";
// str += 1;
// var test = typeof(str);
// if (test.length == 6) {
// test.sign = "typeof的返回结果可能为String";
// }
// //new String(test).sign
// console.log(test.sign);//undefined
// function employee(name , code) {
// this.name = "wangli";
// this.code = "A001"; //里面没用参数啊 this.code = code;没用啊
// }
// var newemp = new employee("zhangming","A002");
// document.write("雇员姓名:"+ newemp.name + "<br>");
// document.write("雇员代号:"+ newemp.code + "<br>");
//输出的结果( A ) 单选
//A . 雇员姓名:wangli 雇员代码:A001
//B . 雇员姓名:zhangming 雇员代码:A002
//C . 雇员姓名:null 雇员代码:null
//D . 编译错误不输出
//闭包问题
// function Person(name, age, sex) {
// var a = 0;
// this.name = name;
// this.age = age;
// this.sex = sex;
// function sss() {
// a++;
// document.write(a);
// }
// this.say = sss;
// }
// var oPerson = new Person();
// oPerson.say();//1
// oPerson.say();//2
// var oPerson1 = new Person();
// oPerson1.say();//1
// var x = 1,y = z = 0;
// function add(n) {
// return n = n + 1;
// }
// y = add(x);
// function add(n) {
// return n = n + 3;
// } //这个会覆盖上面的add
// z = add(x);
// console.log(x);//1
// console.log(y);//4
// console.log(z);//4
//1. 当前字符位的Unicode > 255, 那么该字符字节长度为2
//2. <= 255 为1
// var str = "sfs我就发生";
// function bytesLength(str) {
// var count = 0;
// for(var i = 0; i < str.length; i++){
// if (str.charCodeAt(i) > 255) {
// count = count + 2;
// }else{
// count = count + 1;
// }
// }
// return count;
// }
// console.log(bytesLength(str));
// Person.prototype --原型
// Person.prototype = {} 是祖先
// Person.prototype.name = "hehe";
// Person.prototype.say = function () {
// console.log("hehe");
// }
// function Person(name, age, sex) {
// }
// var person = new Person();
// var person1 = new Person();
// console.log(person1.name);
// console.log(person.name); //hehe继承祖先的属性
//利用原型的特点和概念
// Car.prototype.height = 1400;
// Car.prototype.lang = 400;
// Car.prototype.carName = "BWM";
// function Car(color, owner) {
// this.owner = owner;
// this.color = color;
// }
// var car = new Car('red',"prof.ji");
//原型的增删改查
// Person.prototype.lastName = "deng";//这里是无效的输出undefined
// Person.prototype = {
// height : 1400,
// lang : 4900,
// carName :"BWM"
// }
// function Person(name) {
// this.name = name;
// }
// var person = new Person("xuming");
// function Person() {
// }
// Car.prototype = {
// // constructor : Car;
// constructor : Person
// }
// function Car() {
// }
// var car = new Car();
// function Person() {
// //var this = {
// // __proto__ : Person.prototype
// // };
// }
// var obj = {
// name : "sunny"
// }
// var person = new Person();
// person.__proto__ = obj;
// console.log(person.name);
Person.prototype.name = 'sunny';
function Person() {
//var this = {__proto__ : Person.prototype}
}
var person = new Person();
Person.prototype = {
name : 'charry'
}
// var obj = {name : 'a'};
// var obj1 = obj;
// obj = {name : 'b'};
Person.prototype = {name : "a"};
__proto__ = Person.prototype;
Person.prototype = {name : "b"};
</script>
</body>
</html>