Your SlideShare is downloading. ×
The 'New' Keyword in JavaScript
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

The 'New' Keyword in JavaScript

75
views

Published on

Published in: Software, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
75
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. var simpleObject = { a: 'a' }; { a: 'a' } simpleObject.toString(); // um, where does this function come from?
  • 2. var simpleObject = { a: 'a' }; { a: 'a', __proto__: { ... toString: function, hasOwnProperty: function, ... } }
  • 3. var Demo = function() { ... }; Demo.prototype.doSomething = function() { ... };
  • 4. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = Demo(); myDemo; // undefined myDemo.action() // ERROR window.prop; // 'text'
  • 5. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = Demo(); myDemo; // { prop:'a', action:function } window.prop; // undefined myDemo.action(); // alerts "text"
  • 6. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = new Demo();
  • 7. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = new Demo();
  • 8. • • • • • • • •
  • 9. Object.create(myProtoObject); var obj = Object.create(null); // returns { } obj.toString(); // ERROR
  • 10. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = new Demo(); var Demo = { init: function() { this.prop = 'text'; }, action: function() { alert(this.prop); } }; var myDemo = Object.create(Demo); myDemo.init();