codecademy.com之JavaScript学习
2014-02-15 15:22
429 查看
如何学习javascritpt http://javascriptissexy.com/how-to-learn-javascript-properly/
javascript学习站点 http://www.codecademy.com/zh/tracks/javascript
Boolean
若没有设置或者设置为0,-0,null,"",false,undefined,NaN时为false,其他情况为true
Arrays
创建对象两种方式
(1)object literal notation
(2)object constructor
自定义的构造函数
javascript学习站点 http://www.codecademy.com/zh/tracks/javascript
Data Structures
Data Types: numbers, strings, booleans and arrays.Boolean
若没有设置或者设置为0,-0,null,"",false,undefined,NaN时为false,其他情况为true
Arrays
var myCars=new Array(); var myCars=new Array("Saab","Volvo","BMW"); var myCars=["Saab","Volvo","BMW"];Objects
创建对象两种方式
(1)object literal notation
var myObj = { type: 'fancy',age:24, speak: function(){} //method };
(2)object constructor
var myObj = new Object(); //using a built-in constructor called Object myObj["name"] = "Charlie"; myObj.name = "Charlie";
自定义的构造函数
function Rabbit(adjective) { this.adjective = adjective; var age=12; //private 不能用this修饰 this.describeMyself = function() { console.log("I am a " + this.adjective + " rabbit"); }; } var rabbit1 = new Rabbit("fluffy"); //className.prototype.newMethod = function(){} 给某个类添加方法 Rabbit.prototype.describeMyself = function (){}
Object Oriented
继承// the original Animal class and sayName method function Animal(name, numLegs) { this.name = name; this.numLegs = numLegs; } Animal.prototype.sayName = function() { console.log("Hi my name is " + this.name); }; // define a Penguin class function Penguin(name) { this.name = name; this.numLegs = 2; } // set its prototype to be a new instance of Animal Penguin.prototype = new Animal(); var p =new Penguin("Timmy"); p.sayName();自定义声明的类都继承自Object类
//Object.prototype itself is an object // what is this "Object.prototype" anyway...? var prototypeType = typeof Object.prototype; console.log(prototypeType); //object // now let's examine it! var hasOwn = Object.prototype.hasOwnProperty("hasOwnProperty"); console.log(hasOwn); //true私有化成员和方法
/* Public properties can be accessed from outside the class Private properties can only be accessed from within the class */ function Person(first,last,age) { this.firstname = first; this.lastname = last; this.age = age; var bankBalance = 7500; //var this.bankBalance (不能加this) var returnBalance = function() { return bankBalance; }; // create the new function here this.askTeller = function (){ return returnBalance; } } var john = new Person('John','Smith',30); console.log(john.returnBalance); var myBalanceMethod = john.askTeller(); var myBalance = myBalanceMethod(); console.log(myBalance);
相关文章推荐
- 给大家推荐一个python的学习网站 http://www.codecademy.com
- 给大家推荐一个python的学习网站 http://www.codecademy.com
- 给大家推荐一个python的学习网站 http://www.codecademy.com
- JavaScript菜鸟教程学习 http://www.runoob.com/js/js-tutorial.html
- JavaScript学习笔记之JavaScript调用C#编写的COM组件
- codecademy.com学习过程
- JavaScript核心基础知识学习一
- 每天学习十分钟10之JavaScript
- web开发-javascript编程prototype、this、ajax、json、结构体和数组-学习笔记十四
- JavaScript学习—原型和继承
- 最近在ArcGIS Engine开发中关于调用gp工具过程出现COM 组件的调用返回了错误 HRESULT E_FAIL 错误的解决方法 和 学习oracle中遇到的一些问题总结
- javascript学习(5) Bom学习
- 方法返回javascript学习实录 之二(数组操作等等utils) --刘啸尘
- 通过使用Chrome的开发者工具来学习JavaScript
- 【转】如何学习Javascript
- JavaScript的instanceof运算符学习教程
- JavaScript学习-window对象
- javascript 学习记录
- 学习JavaScript你必须掌握的8大知识点! 推荐