Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 2 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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;