Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Es6-class记录 #2

Open
Gtanxingwen opened this issue Jul 28, 2017 · 0 comments
Open

Es6-class记录 #2

Gtanxingwen opened this issue Jul 28, 2017 · 0 comments

Comments

@Gtanxingwen
Copy link
Owner

Gtanxingwen commented Jul 28, 2017

class Point {
        constructor(x, y) {
            this.x = x;
            this.y = y;
        }
        add() {
            return this.x + this.y;
        }
    }
const b = new Point(1, 3);
console.log(b)
console.log(b.__proto__)
console.log(b.constructor)
console.log(Point.prototype)
console.log(Point.prototype.constructor)
console.log('实例对象的原型指向类的prototype属性');
console.log('b.__proto__ === Point.prototype');
console.log(b.__proto__ === Point.prototype);
console.log('类的原型属性prototype属性的构造函数指向类本身===类本身就指向构造函数');
console.log('Point.prototype.constructor === Point');
console.log(Point.prototype.constructor === Point);
console.log('实例对象的构造函数指向类');
console.log('b.constructor === Point');
console.log(b.constructor === Point);
console.log('实例对象的constructor方法指向类原型的构造方法');
console.log('b.constructor === Point.prototype.constructor');
console.log(b.constructor === Point.prototype.constructor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant