Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. function User() {
  2. this.name = name;
  3. }
  4.  
  5. User.prototype.printName = function() {
  6. console.log (this.name)
  7. }
  8.  
  9. let demoUser = {
  10. name: "Demo user Name"
  11. }
  12.  
  13. const john = new User("John");
  14. const binded = john.printName.bind(demoUser)
  15. john.printName();
  16. binded();
  17.  
  18.  
  19. // პროტოტიპირების გამარტივებული ვარიანტი (სინტაქსურად მეტად გასაგები)
  20. // private, protected, public ცვლადის სიტყვები
  21. class Person {
  22. constructor(firstName, lastName) {
  23. this.age = 0;
  24. this.birthday = 0;
  25. this.firstName = firstName;
  26. this.lastName = lastName;
  27.  
  28.  
  29. }
  30. get firstName () {
  31. return this._firstName
  32. }
  33.  
  34. set firstName() {
  35. if (typeof value != 'string' throw new SyntaxError ("Invalid Value") )
  36. this._firstName = value
  37.  
  38. }
  39.  
  40. sayName() {
  41. alert(`${this.firstName} ${this.lastName}`);
  42. }
  43. }
  44.  
  45. const person = new Person("John", "Doe");
  46. person.sayName();
  47. // person.firstName = 2019; რადგან ჯავასკრიპტში ყველაფერი public ია, მეთოდების შეცვლა ძალიან მარტივია.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement