• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽
 

【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽

on

  • 1,200 views

面向Java程序员的JavaScript教程

面向Java程序员的JavaScript教程

Statistics

Views

Total Views
1,200
Views on SlideShare
1,127
Embed Views
73

Actions

Likes
3
Downloads
30
Comments
0

1 Embed 73

http://taobaojstraining.info 73

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽 【第一季第三期】Thinking in Javascript & OO in Javascript - 清羽 Presentation Transcript

  • Java & Script
  • JavaScript Java
  • , Java JavaScript , Java JavaScript
  • Java + Script = Groovy || JRuby || Scala
  • Java + Script |!=| JavaScript
  • JavaScript is
  • JavaScript is JavaScript
  • +
  • Code: new Boolean(true) == true new Boolean(true) === false
  • Code: var a = “”; if (a) { alert(a); }
  • • new Boolean(true) true • == === • if (a) a
  • • • •
  • •5 null undefined
  • • 20 • true • ”hello, world!” • [12, 30, true, “hello”] • {name: “qingyu”, id: 17300}
  • • == === • === == • ECMA
  • Tips • • === ==
  • Code: var price = 100; function doSomething() { var doublePrice = price * 2; var price = 200; var halfPrice = price / 2; alert(doublePrice); alert(halfPrice); } doSomething(); alert(price);
  • Code: var color = “red”; if (true) { var color = “blue”; alert(color); } alert(color);
  • • var doublePrice = price * 2 var halfPrice = price / 2 price • color
  • • •
  • • var var •
  • Tips •
  • Code: var a = 0 && true; var b = true && 2; var c = 0 || 3; var cfg = {maxHeight: 200}; var d = cfg.height || cfg.maxHeight;
  • Code: // 0 var check = function(obj) { return !!(obj || obj === 0); };
  • • && || • && || • !!a a
  • Tips • || • !!
  • Code: (function() { //code here })();
  • var fn = function() { //code here }; fn();
  • var fn = function() { //code here }; fn();
  • var fn = function() { //code here }; fn();
  • (function() { //code here }) ();
  • Code: var createComparisonFunction = function(propertyName) { return function(object1, object2) { var value1 = object1[propertyName], value2 = object2[propertyName]; if (value1 < value2) { return -1; } else if (value1 > value2) { return 1; } else { return 0; } }; } var fn = createComparisonFunction(‘id’);
  • • • •
  • Tips •
  • Code: var sum = function() { var result = 0; for(var i = 0, len = arguments.length; i < len; I++) { result += arguments[i]; } return result; }; var total = sum(10, 20, 30);
  • Code: function factorial(num) { if (num <= 1) { return 1; } else { return num * arguments.callee(num - 1); } }
  • Code: function sum(num1, num2) { return num1 + num2; } function callSum1(num1, num2) { return sum.apply(this, [num1, num2]); } function callSum2(num1, num2) { return sum.call(this, num1, num2); }
  • • Function • • arguments • apply call
  • Code: window.color = “red”; var obj = {color: “blue”}; function sayColor() { alert(this.color); } sayColor(); obj.sayColor = sayColor; obj.sayColor();
  • Code: var Dog = function(msg) { this.msg = msg; this.shout = function() { alert(this.msg); }; this.waitAndShout = function() { setTimeout(function() { alert(this.msg) }, 5000); }; };
  • this • Java • this • this window this
  • Code: var Person = function(name) { this.name = name; this.sayName = function() { alert(this.name); }; }; var person1 = new Person(“Jack”); person1.sayName();
  • Code: var Person = function() {}; Person.prototype.name = “Jack”; Person. prototype.sayName = function() { alert(this.name); }; var person1 = new Person(); person1.sayName();
  • • •
  • Tips • Peron Person.prototype
  • Code: function SuperType() { this.property = true; } SuperType.prototype.getSuperValue = function() { return this.property; }; function SubType() { this.subProperty = false; } SubType.prototype = new SuperType(); SubType.prototype.getSubValue = function() { return this. subProperty; };
  • Code: var instance = new SubType(); alert(instance.getSuperValue()); alert(instance.getSubValue()); alert(instance instanceof Object); alert(instance instanceof SuperType); alert(instance instanceof SubType);
  • • 1. ; 2. SubType.prototype; 3. SuperType.prototype;
  • • • • •
  • YUI
  • Thanks