Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function User() {
- this.name = name;
- }
- User.prototype.printName = function() {
- console.log (this.name)
- }
- let demoUser = {
- name: "Demo user Name"
- }
- const john = new User("John");
- const binded = john.printName.bind(demoUser)
- john.printName();
- binded();
- // პროტოტიპირების გამარტივებული ვარიანტი (სინტაქსურად მეტად გასაგები)
- // private, protected, public ცვლადის სიტყვები
- class Person {
- constructor(firstName, lastName) {
- this.age = 0;
- this.birthday = 0;
- this.firstName = firstName;
- this.lastName = lastName;
- }
- get firstName () {
- return this._firstName
- }
- set firstName() {
- if (typeof value != 'string' throw new SyntaxError ("Invalid Value") )
- this._firstName = value
- }
- sayName() {
- alert(`${this.firstName} ${this.lastName}`);
- }
- }
- const person = new Person("John", "Doe");
- person.sayName();
- // person.firstName = 2019; რადგან ჯავასკრიპტში ყველაფერი public ია, მეთოდების შეცვლა ძალიან მარტივია.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement