Skip to content

Why is the way 'this' passed was in different way in NamespaceExtension and ConstructorExtension? #6

@mmis1000

Description

@mmis1000

Looks like the ways arguments was passed will be altered depends on how you organize the extension?

Besides that.

The ConstructorExtension don't expose the object the method was on (a.k.a. ext.prototype) to the method.

While NamespaceExtension by default do that (ext itself was called as this).
Is this ever required?

Shouldn't the method be able to just refer the object that host it as ext (or whatever) if it must do it?

const ext = {
  method (self, arg1, arg2) { 
    return this.method2(self)
    // why do you want to use `this` to refer 'ext' here ?
    // Isn't it able to just do `this::ext:method2()`
    //   if it was passed in same way the class method do?
  },
  method2 (self, arg1, arg2) {}
}

someObj::ext:method()

And this breaks compatibility of namespace import and named import

// file a.js
export function A(self) {
  console.log(self.a)
}

// file b.js
import { ::A } from 'a.js'
import * as a from 'a.js'

const obj {
 a: 'hello'
}

obj::a:A() // this would work
obj::A() // this unfortunately not because it pass this as this instead of arguments[0]

That would makes refactor from namespace import to named import require a complete code rewrite because it breaks the semantic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions