Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

63 строки
1.3 KiB

  1. function Scope(data, parent, context) {
  2. if (typeof data != 'object') {
  3. data = { $value: data };
  4. }
  5. this.data = data;
  6. this.parent = parent;
  7. this.context = context;
  8. };
  9. Scope.prototype = {
  10. create: function(data, context) {
  11. return new Scope(data, this, context);
  12. },
  13. get: function(name) {
  14. if (this.data[name] !== undefined) {
  15. return this.data[name];
  16. }
  17. if (this.parent) {
  18. return this.parent.get(name);
  19. }
  20. return undefined;
  21. },
  22. set: function(name, value) {
  23. if (typeof name == 'object') {
  24. for (let prop in name) {
  25. this.set(prop, name[prop]);
  26. }
  27. } else {
  28. this.data[name] = value;
  29. if (this.context) {
  30. this.context[name] = value;
  31. }
  32. }
  33. },
  34. has: function(name) {
  35. if (this.data[name] !== undefined) {
  36. return true;
  37. }
  38. if (this.parent) {
  39. return this.parent.has(name);
  40. }
  41. return false;
  42. },
  43. remove: function(name) {
  44. delete this.data[name];
  45. if (this.context) {
  46. delete this.context[name];
  47. }
  48. },
  49. }
  50. module.exports = Scope;