Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var foo = {
- a: 5,
- b: 6,
- c: this.a + this.b // Doesn't work
- };
- var foo = {
- a: 5,
- b: 6,
- get c () {
- return this.a + this.b;
- }
- };
- foo.c; // 11
- var foo = {
- a: 5,
- b: 6,
- init: function() {
- this.c = this.a + this.b;
- return this;
- }
- }.init();
- var foo = {
- a: 5,
- b: 6
- };
- foo.c = foo.a + foo.b;
- var foo = function(o) {
- o.c = o.a + o.b;
- return o;
- }({a: 5, b: 6});
- function buildFoo(a, b) {
- var o = {a: a, b: b};
- o.c = o.a + o.b;
- return o;
- }
- var foo = buildFoo(5, 6);
- var foo = new function () {
- this.a = 5;
- this.b = 6;
- this.c = this.a + this.b;
- };
- var foo = function() {
- var a = 5;
- var b = 6;
- var c = a + b;
- return {
- a: a,
- b: b,
- c: c
- }
- }();
- const foo = {
- a: 5,
- b: 6,
- get c() {
- delete this.c;
- return this.c = this.a + this.b
- }
- };
- foo // {a: 5, b: 6}
- foo.c // 11
- foo // {a: 5, b: 6 , c: 11}
- var a, b
- var foo = {
- a: a = 5,
- b: b = 6,
- c: a + b
- }
- function createMyObject() {
- var count = 0, self
- return {
- a: self = {
- log: function() {
- console.log(count++)
- return self
- }
- }
- }
- }
- function createMyObject() {
- var count = 0
- return {
- a: {
- log: function() {
- console.log(count++)
- return this
- }
- }
- }
- }
- var o = createMyObject()
- var log = o.a.log
- o.a.log().log() // this refers to the o.a object so the chaining works
- log().log() // this refers to the window object so the chaining fails!
- class Foo {
- constructor(){
- this.a = 5;
- this.b = 6;
- this.c = this.a + this.b;
- }
- }
- const foo = new Foo();
- function Obj() {
- this.a = 5;
- this.b = this.a + 1;
- // return this; // commented out because this happens automatically
- }
- var o = new Obj();
- o.b; // === 6
- var foo = function() {
- var that = {};
- that.a = 7;
- that.b = 6;
- that.c = function() {
- return that.a + that.b;
- }
- return that;
- };
- var fooObject = foo();
- fooObject.c(); //13
- var foo = {
- a: function(){return 5}(),
- b: function(){return 6}(),
- c: function(){return this.a + this.b}
- }
- console.log(foo.c())
- var foo = {
- get a(){return 5},
- get b(){return 6},
- get c(){return this.a + this.b}
- }
- // console.log(foo.c);
- var x = { a: 1, b: 2, c: a + b } // not defined
- var y = { a: 1, b: 2, c: y.a + y.b } // not defined
- var x = { a: 1, b: 2 };
- x.c = x.a + x.b; // apply computed property
- var x = 9 //this is really window.x
- var bar = {
- x: 1,
- y: 2,
- foo: new function(){
- this.a = 5, //assign value
- this.b = 6,
- this.c = this.a + this.b; // 11
- },
- z: this.x // 9 (not 1 as you might expect, b/c *this* refers `window` object)
- };
- var foo = {
- bar:(function(){
- window.temp = "qwert";
- return window.temp;
- })(),
- baz: window.temp
- };
- const module = (state) => ({
- a: 1,
- oneThing() {
- state.b = state.b + this.a
- },
- anotherThing() {
- this.oneThing();
- state.c = state.b + this.a
- },
- });
- const store = {b: 10};
- const root = module(store);
- root.oneThing();
- console.log(store);
- root.anotherThing();
- console.log(store);
- console.log(root, Object.keys(root), root.prototype);
- Object.prototype.assignOwnProVal
- = function (to,from){
- function compose(obj,string){
- var parts = string.split('.');
- var newObj = obj[parts[0]];
- if(parts[1]){
- parts.splice(0,1);
- var newString = parts.join('.');
- return compose(newObj,newString);
- }
- return newObj;
- }
- this[to] = compose(this,from);
- }
- var obj = { name : 'Gaurav', temp :
- {id : [10,20], city:
- {street:'Brunswick'}} }
- obj.assignOwnProVal('street','temp.city.street');
- obj.assignOwnProVal('myid','temp.id.1');
- var foo = {
- a: 5,
- b: 6,
- c: function() {
- return this.a + this.b;
- },
- d: [10,20,30],
- e: function(x) {
- this.d.push(x);
- return this.d;
- }
- };
- foo.c(); // 11
- foo.e(40); // foo.d = [10,20,30,40]
- var foo = ((a,b) => ({
- a,
- b,
- c: a + b
- }))(a,b);
- let processingState = ((indexOfSelectedTier) => ({
- selectedTier,
- indexOfSelectedTier,
- hasUpperTierSelection: tiers.slice(0,indexOfSelectedTier)
- .some(t => pendingSelectedFiltersState[t.name]),
- }))(tiers.indexOf(selectedTier));
- var foo = {
- a: 5,
- b: 6,
- };
- var foo2 = {
- c: foo.a + foo.b
- };
- Object.assign(foo, foo2);
- foo = {...foo, ...foo2};
- {
- "a":5,
- "b":6,
- "c":11
- }
- {
- a: ...,
- b: "${this.a + this.a}",
- }
- class asd {
- def = new class {
- ads= 'asd';
- qwe= this.ads + '123';
- };
- // this method is just to check/test this solution
- check(){
- console.log(this.def.qwe);
- }
- }
- // these two lines are just to check
- let instance = new asd();
- instance.check();
- class asd {
- def = new class {
- ads= 'asd';
- qwe= this.ads + '123';
- };
- var asd = {
- def : {
- ads:'asd',
- qwe: this.ads + '123';, //ILLEGAL CODE; just to show ideal scenario
- }
- }
- class CONSTANT {
- static readonly PATH = new class {
- /** private visibility because these relative paths don't make sense for direct access, they're only useful to path class
- *
- */
- private readonly RELATIVE = new class {
- readonly AFTER_EFFECTS_TEMPLATE_BINARY_VERSION: fs.PathLike = '\assets\aep-template\src\video-template.aep';
- readonly AFTER_EFFECTS_TEMPLATE_XML_VERSION: fs.PathLike = '\assets\aep-template\intermediates\video-template.aepx';
- readonly RELATIVE_PATH_TO_AFTER_EFFECTS: fs.PathLike = '\Adobe\Adobe After Effects CC 2018\Support Files\AfterFX.exe';
- readonly OUTPUT_DIRECTORY_NAME: fs.PathLike = '\output';
- readonly INPUT_DIRECTORY_NAME: fs.PathLike = '\input';
- readonly ASSETS_DIRECTORY_NAME: fs.PathLike = '\assets';
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement