【学习笔记】JS基于原型的面向对象

/*|------------------------------------------------------|
 *|--js是基于原型prototype而不是类class的面相对象语言----|
 *|--js只有对象和对象的实例,没有class-------------------|
 *|--Z_LY-2015-11-15-------------------------------------|
 *|------------------------------------------------------|
 */


node = new Object();

node.name = 'tufei';
node.blood = 10;
node.speed = 30;

var span = document.getElementById('wod');
var c = 0;

function altTest(){
    //open('http://baidu.com');
    //var t = setTimeout('alert("hahahah")',5000);
    span.innerHTML = c;
    c++;
    setTimeout('altTest()',1000);   
}

document.write(node.name+'<br>');

function protyp(){
    this.name = 'Lili';//this声明
    this.age = 22;
    this.height= 9;
    this.runaway = run;
    function run(){
        document.write('I am runing<br/>');
    }
}

var hmm = new protyp();

document.write(hmm.name+'<br>');

hmm.runaway();

for(x in hmm){//x居然是健
    document.write(x+'='+hmm[x]+'<br>');//这里不能用hmm.x
}

//JavaScript 中的所有数字都存储为根为 10 的 64 位(8 比特)的浮点数

document.write('location='+location.hostname+'<br>');

  JS没有定义的class,只有基于prototype的对象和对象实例,实现梅固定的写法,搞得有点复杂,也灵活吧!!!随便学了点,高级篇复习再补上!

posted @ 2015-11-19 15:37  逢妹必问约  阅读(242)  评论(0编辑  收藏  举报