Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.29 KB | None | 0 0
  1. var foo = {
  2. a: 5,
  3. b: 6,
  4. c: this.a + this.b // Doesn't work
  5. };
  6.  
  7. var foo = {
  8. a: 5,
  9. b: 6,
  10. get c () {
  11. return this.a + this.b;
  12. }
  13. };
  14.  
  15. foo.c; // 11
  16.  
  17. var foo = {
  18. a: 5,
  19. b: 6,
  20. init: function() {
  21. this.c = this.a + this.b;
  22. return this;
  23. }
  24. }.init();
  25.  
  26. var foo = {
  27. a: 5,
  28. b: 6
  29. };
  30. foo.c = foo.a + foo.b;
  31.  
  32. var foo = function(o) {
  33. o.c = o.a + o.b;
  34. return o;
  35. }({a: 5, b: 6});
  36.  
  37. function buildFoo(a, b) {
  38. var o = {a: a, b: b};
  39. o.c = o.a + o.b;
  40. return o;
  41. }
  42.  
  43. var foo = buildFoo(5, 6);
  44.  
  45. var foo = new function () {
  46. this.a = 5;
  47. this.b = 6;
  48. this.c = this.a + this.b;
  49. };
  50.  
  51. var foo = function() {
  52. var a = 5;
  53. var b = 6;
  54. var c = a + b;
  55.  
  56. return {
  57. a: a,
  58. b: b,
  59. c: c
  60. }
  61. }();
  62.  
  63. const foo = {
  64. a: 5,
  65. b: 6,
  66. get c() {
  67. delete this.c;
  68. return this.c = this.a + this.b
  69. }
  70. };
  71.  
  72. foo // {a: 5, b: 6}
  73. foo.c // 11
  74. foo // {a: 5, b: 6 , c: 11}
  75.  
  76. var a, b
  77. var foo = {
  78. a: a = 5,
  79. b: b = 6,
  80. c: a + b
  81. }
  82.  
  83. function createMyObject() {
  84. var count = 0, self
  85. return {
  86. a: self = {
  87. log: function() {
  88. console.log(count++)
  89. return self
  90. }
  91. }
  92. }
  93. }
  94.  
  95. function createMyObject() {
  96. var count = 0
  97. return {
  98. a: {
  99. log: function() {
  100. console.log(count++)
  101. return this
  102. }
  103. }
  104. }
  105. }
  106.  
  107. var o = createMyObject()
  108. var log = o.a.log
  109. o.a.log().log() // this refers to the o.a object so the chaining works
  110. log().log() // this refers to the window object so the chaining fails!
  111.  
  112. class Foo {
  113. constructor(){
  114. this.a = 5;
  115. this.b = 6;
  116. this.c = this.a + this.b;
  117. }
  118. }
  119.  
  120. const foo = new Foo();
  121.  
  122. function Obj() {
  123. this.a = 5;
  124. this.b = this.a + 1;
  125. // return this; // commented out because this happens automatically
  126. }
  127.  
  128. var o = new Obj();
  129. o.b; // === 6
  130.  
  131. var foo = function() {
  132. var that = {};
  133.  
  134. that.a = 7;
  135. that.b = 6;
  136.  
  137. that.c = function() {
  138. return that.a + that.b;
  139. }
  140.  
  141. return that;
  142. };
  143. var fooObject = foo();
  144. fooObject.c(); //13
  145.  
  146. var foo = {
  147. a: function(){return 5}(),
  148. b: function(){return 6}(),
  149. c: function(){return this.a + this.b}
  150. }
  151.  
  152. console.log(foo.c())
  153.  
  154. var foo = {
  155. get a(){return 5},
  156. get b(){return 6},
  157. get c(){return this.a + this.b}
  158. }
  159. // console.log(foo.c);
  160.  
  161. var x = { a: 1, b: 2, c: a + b } // not defined
  162. var y = { a: 1, b: 2, c: y.a + y.b } // not defined
  163.  
  164. var x = { a: 1, b: 2 };
  165.  
  166. x.c = x.a + x.b; // apply computed property
  167.  
  168. var x = 9 //this is really window.x
  169. var bar = {
  170. x: 1,
  171. y: 2,
  172. foo: new function(){
  173. this.a = 5, //assign value
  174. this.b = 6,
  175. this.c = this.a + this.b; // 11
  176. },
  177. z: this.x // 9 (not 1 as you might expect, b/c *this* refers `window` object)
  178. };
  179.  
  180. var foo = {
  181. bar:(function(){
  182. window.temp = "qwert";
  183. return window.temp;
  184. })(),
  185. baz: window.temp
  186. };
  187.  
  188. const module = (state) => ({
  189. a: 1,
  190. oneThing() {
  191. state.b = state.b + this.a
  192. },
  193. anotherThing() {
  194. this.oneThing();
  195. state.c = state.b + this.a
  196. },
  197. });
  198.  
  199. const store = {b: 10};
  200. const root = module(store);
  201.  
  202. root.oneThing();
  203. console.log(store);
  204.  
  205. root.anotherThing();
  206. console.log(store);
  207.  
  208. console.log(root, Object.keys(root), root.prototype);
  209.  
  210. Object.prototype.assignOwnProVal
  211. = function (to,from){
  212. function compose(obj,string){
  213. var parts = string.split('.');
  214. var newObj = obj[parts[0]];
  215. if(parts[1]){
  216. parts.splice(0,1);
  217. var newString = parts.join('.');
  218. return compose(newObj,newString);
  219. }
  220. return newObj;
  221. }
  222. this[to] = compose(this,from);
  223. }
  224. var obj = { name : 'Gaurav', temp :
  225. {id : [10,20], city:
  226. {street:'Brunswick'}} }
  227. obj.assignOwnProVal('street','temp.city.street');
  228. obj.assignOwnProVal('myid','temp.id.1');
  229.  
  230. var foo = {
  231. a: 5,
  232. b: 6,
  233. c: function() {
  234. return this.a + this.b;
  235. },
  236.  
  237. d: [10,20,30],
  238. e: function(x) {
  239. this.d.push(x);
  240. return this.d;
  241. }
  242. };
  243. foo.c(); // 11
  244. foo.e(40); // foo.d = [10,20,30,40]
  245.  
  246. var foo = ((a,b) => ({
  247. a,
  248. b,
  249. c: a + b
  250. }))(a,b);
  251.  
  252. let processingState = ((indexOfSelectedTier) => ({
  253. selectedTier,
  254. indexOfSelectedTier,
  255. hasUpperTierSelection: tiers.slice(0,indexOfSelectedTier)
  256. .some(t => pendingSelectedFiltersState[t.name]),
  257. }))(tiers.indexOf(selectedTier));
  258.  
  259. var foo = {
  260. a: 5,
  261. b: 6,
  262. };
  263.  
  264. var foo2 = {
  265. c: foo.a + foo.b
  266. };
  267.  
  268. Object.assign(foo, foo2);
  269.  
  270. foo = {...foo, ...foo2};
  271.  
  272. {
  273. "a":5,
  274. "b":6,
  275. "c":11
  276. }
  277.  
  278. {
  279. a: ...,
  280. b: "${this.a + this.a}",
  281. }
  282.  
  283. class asd {
  284. def = new class {
  285. ads= 'asd';
  286. qwe= this.ads + '123';
  287. };
  288.  
  289. // this method is just to check/test this solution
  290. check(){
  291. console.log(this.def.qwe);
  292. }
  293. }
  294.  
  295. // these two lines are just to check
  296. let instance = new asd();
  297. instance.check();
  298.  
  299. class asd {
  300. def = new class {
  301. ads= 'asd';
  302. qwe= this.ads + '123';
  303. };
  304.  
  305. var asd = {
  306. def : {
  307. ads:'asd',
  308. qwe: this.ads + '123';, //ILLEGAL CODE; just to show ideal scenario
  309. }
  310. }
  311.  
  312. class CONSTANT {
  313. static readonly PATH = new class {
  314. /** private visibility because these relative paths don't make sense for direct access, they're only useful to path class
  315. *
  316. */
  317. private readonly RELATIVE = new class {
  318. readonly AFTER_EFFECTS_TEMPLATE_BINARY_VERSION: fs.PathLike = '\assets\aep-template\src\video-template.aep';
  319. readonly AFTER_EFFECTS_TEMPLATE_XML_VERSION: fs.PathLike = '\assets\aep-template\intermediates\video-template.aepx';
  320. readonly RELATIVE_PATH_TO_AFTER_EFFECTS: fs.PathLike = '\Adobe\Adobe After Effects CC 2018\Support Files\AfterFX.exe';
  321. readonly OUTPUT_DIRECTORY_NAME: fs.PathLike = '\output';
  322. readonly INPUT_DIRECTORY_NAME: fs.PathLike = '\input';
  323. readonly ASSETS_DIRECTORY_NAME: fs.PathLike = '\assets';
  324. };
  325. }
  326. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement