var simpleObject = {
a: 'a'
};
{
a: 'a'
}
simpleObject.toString(); // um, where does this function come from?
var simpleObject = {
a: 'a'
};
{
a: 'a',
__proto__: {
...
toString: function,
hasOwnProperty: function,
...
}
}
var Demo = function() {
...
};
Demo.prototype.doSomething = function() {
...
};
var Demo = function() {
this.prop = 'text';
};
Demo.prototype.action = function() {
alert(this.prop);
};
var myDemo = Demo...
var Demo = function() {
this.prop = 'text';
};
Demo.prototype.action = function() {
alert(this.prop);
};
var myDemo = Demo...
var Demo = function() {
this.prop = 'text';
};
Demo.prototype.action = function() {
alert(this.prop);
};
var myDemo = new ...
var Demo = function() {
this.prop = 'text';
};
Demo.prototype.action = function() {
alert(this.prop);
};
var myDemo = new ...
•
•
•
•
•
•
•
•
Object.create(myProtoObject);
var obj = Object.create(null); // returns { }
obj.toString(); // ERROR
var Demo = function() {
this.prop = 'text';
};
Demo.prototype.action = function() {
alert(this.prop);
};
var myDemo = new ...
The 'New' Keyword in JavaScript
The 'New' Keyword in JavaScript
The 'New' Keyword in JavaScript
The 'New' Keyword in JavaScript
The 'New' Keyword in JavaScript
The 'New' Keyword in JavaScript
Upcoming SlideShare
Loading in …5
×

The 'New' Keyword in JavaScript

281 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
281
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

The 'New' Keyword in JavaScript

  1. 1. var simpleObject = { a: 'a' }; { a: 'a' } simpleObject.toString(); // um, where does this function come from?
  2. 2. var simpleObject = { a: 'a' }; { a: 'a', __proto__: { ... toString: function, hasOwnProperty: function, ... } }
  3. 3. var Demo = function() { ... }; Demo.prototype.doSomething = function() { ... };
  4. 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. 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. 6. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = new Demo();
  7. 7. var Demo = function() { this.prop = 'text'; }; Demo.prototype.action = function() { alert(this.prop); }; var myDemo = new Demo();
  8. 8. • • • • • • • •
  9. 9. Object.create(myProtoObject); var obj = Object.create(null); // returns { } obj.toString(); // ERROR
  10. 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();

×