Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Class(){}
- var instance1 = new Class();
- var instance2 = {};
- instance2.constructor = Class;
- instance2.__proto__ = Class.prototype;
- //rototype when instantiate, you already set prototype's ___proto__ to the function's constructor
- Class.apply(instance2);
- instance[1|2].constructor == Class
- instance[1|2].__proto__ = Class.prototype
- instance[1|2] instanceof Class = true
- //What does a function's prototype do?
- function Circle(radius) {
- this.radius = radius;
- }
- Circle.prototype.area = function() {
- return this.radius * this.radius * Math.Pi;
- }
- var instance = new Circle(5);
- instance.area() ==> 78.5275
- instance.constructor == Circle
- instance.__proto__ == Circle.prototype
- instance instanceof Circle = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement