/**
*
*/
function persion() {
//
this.age = 123;
}
// persion
var p = new persion();
// //
// alert(p["age"]);
// alert(p.age);
// , ,
//
p.sex = "male";
// alert(p.sex);
//
p.getSex = function() {
return this.sex;
}
// alert(p.getSex());
//
p.sex = "female";
// alert(p.sex);
//
p.sex = undefined;
// alert(p.sex);
//
p.getSex = undefined;
// alert(p.getSex());
// ---------------------------------------------------
/**
* {}
*/
//
var obj = {};
var man = {
name : "fy",// name , fy
favoriteColor : ['black', 'red', 'green'],
sayHello : function() {// sayHello
alert("hello world!!");
}
};
// man sayHello
//man.sayHello();
// ---------------------------------------------------
/**
* protoType
*/
//
function woman(){
//empty
}
// prototype , getSex();
woman.prototype.getSex = function(){
alert("I'm a woman");
};
// woman
var w = new woman();
//w.getSex();
// ---------------------------------------------------
/**
*
*/
function boy(){
var pp = "peope are private";// pp
function pm(){// pm
alert(pp);
}
this.getPp = function(){
//
pp = "peope are private???";
},
this.getPm = function(){
//
pm();
};
}
// boy
var boy = new boy();
//boy.getPm();
//boy.getPp();
//boy.getPm();
// ---------------------------------------------------
/**
*
*/
function girl(){
}
//
girl.staticProperty = "class level";
//
girl.staticMethod = function(){
alert("static method!!!");
};
//
// alert(girl.staticProperty);
// girl.staticMethod();
// ---------------------------------------------------
/**
* for(..in..)
*/
//
var style = {
color:'#FF0000',
backgroundColor:'#0000FF',
borderWidth:'2px'
};
function setStyle(_style){
//
var element = getElement();
//element.style = _style;
for(var p in _style){
element.style[p] = _style[p];
}
}
function getElement(){
return document.getElementById("aa");
}
//setStyle(style);
// ---------------------------------------------------
/**
* prototype
*/
function father(){
}
father.prototype = {
m1 : function(){
alert(1);
}
};
function child(){
}
// child father
child.prototype = father.prototype;
child.prototype.method = function(){
alert("2");
};
var f = new father();
var c = new child();
//f.method();
//c.method();
// ---------------------------------------------------
/**
* prototype
*/
function father1(){
}
father1.prototype = {
method1:function(){
alert(1);
},
method2:function(){
alert(2);
}
};
function child1(){
}
// child1 father1
for(var p in father1.prototype){
child1.prototype[p] = father1.prototype[p];
}
// father1 method1
child1.prototype.method = function(){
alert(11);
};
//
var f1 = new father1();
var c1 = new child1();
// method1
// f1.method1();
// c1.method();
// ---------------------------------------------------
/**
* prototype
*/
function father2(){
}
// inherit
Function.prototype.inherit = function(baseClass){
for(var p in baseClass){
this.prototype[p] = baseClass.prototype[p];
}
}
father2.prototype = {
method1:function(){
alert(1);
},
method2:function(){
alert(2);
}
};
function child2(){
}
// child1 father1
// for(var p in father2.prototype){
//
// child2.prototype[p] = father2.prototype[p];
// }
child2.inherit(father2);
// father1 method1
child2.prototype.method = function(){
alert(11);
};
//
var f2 = new father2();
var c2 = new child2();
// method1
f2.method1();
c2.method();