Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

JavaScript

No description
by

Yihong Wang

on 7 August 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of JavaScript

JavaScript Object Oriented Programming
Oops! There is no Class in JavaScript
Prototype
A prototype is just a plain object, that happens to share it's behaviours with another object — it acts as the object's parent.
Constructor
magical variable
Encapsulation
closure and scope chain
Compose Dynamically
modify prototype object, add/remove properties on the fly.
1. var obj = Object.create( prototype )
2. var obj = { __proto__ : prototype }
However, Inheritance exists in JavaScript
Prototype Rocks!!
3. function Book() { ..... }
Book.prototype = { .... }
var abook = new Book()
this
call a function via
new
prototype.constructor
function MyObject ( a, b) {
this.x = a;
this.y = b;
}

var obj = new MyObject( 10, 12);

obj.constructor == MyObject; //true
function MyObject ( a , b ) {
var x_ = a;
this.getX = function () {
return x_;
}
this.setX = function ( x ) {
x_ = x;
}
}
Override
self first then prototype chain
function Cat() { ... };
Cat.prototype.purr = function () { ... };

var mix = { __proto__ : new Cat(), purr = function () {... } };
mix.purr();
var parent = {};
var child = Object.create ( parent );

parent.fileBug = function () { ... };
child.fileBug();

var sqa = { comp : 'datapower.js' };

parent.__proto__ = sqa;
child.getComp = function { return this.comp };
child.getComp();

Practices
functions are named with an initial capital
Constructor
Prototype vs Property
function Cat() {
this.purr = function () { ... }
}
Everything is Object
function Mamal () { ...... }
Mamal.prototype.getName = function () { .... }

function Cat () {}
Cat.prototype = new Mamal();
Cat.prototype.purr = function () { ... };

var acat = new Cat();
acat.purr();
acat.getName();

What happens : new MyObject()
var that = Object.create ( MyObject.prototype )
var other = MyObject.apply ( that, arguments )
return (typeof other === 'object' && other) || that
Abstraction
function AbstractSet () {
throw new Error("Can't instantiate abstract classes");
}
AbstractSet.prototype.add = function () {
throw new Error("abstract method");
}

function ArraySet () {
this.add = function () { ... }
}
ArraySet.prototype = AbstractSet.prototype;
Full transcript