, , , , , , bable es6, vue js , .
, , .
{, inline ) ( , , - :))
, , bundle.js
, , coed , , , .
, es6, bable
: code.js, main.js (main.js) , .., code.js
code.js/ socket.js
const code = function() {
console.log(this);
console.log(this.socket);
const test = () => {
console.log(this);
}
test()
}
export default code
my main.js/ vue
import socketCode from './code';
const main = {
socket: 'test',
init() {
console.log(this);
let socketCodebinded = socketCode.bind(this); // magical this binding
socketCodebinded(); // this will do all event-binding things
//and good thing is that it will have "this" as context so no breaking of references
... continue other code or add another lib ;) like above
}
}
main.init();
/,
code.js/socket.js , main.js.