javascript - How to call a class' constructor to 'create' from Chrome console? -
question: how can create var a1 = animal('red', 4, 'frank);
console in chrome??
i've created class while playing around es6.
"use strict"; class animal{ constructor(color, legs, name){ this.color = color; this.legs = legs; this.name = name; } } export default animal;
chrome console input + error
> var frank = new animal('red', 4, 'henry'); uncaught referenceerror: animal not defined @ <anonymous>:2:17 @ object.injectedscript._evaluateon (<anonymous>:895:140) @ object.injectedscript._evaluateandwrap (<anonymous>:828:34) @ object.injectedscript.evaluate (<anonymous>:694:21)(anonymous function) @ vm13736:2injectedscript._evaluateon @ vm13308:895injectedscript._evaluateandwrap @ vm13308:828injectedscript.evaluate @ vm13308:694
index.html
<script src="../jspm_packages/system.js"></script> <script src="../config.js"></script> <script> system.import('reflect-metadata') .then(function(){ return system.import('client/app/animal/animal'); }) .then(function(animal){ window.animal = animal; }) .catch(console.log.bind(console)); </script>
update: i've updated second promise set animal window && i've tested in console. :( no luck still
this bablejs downcompile class to:
var animal = function animal(color, legs, name) { this.color = color; this.legs = legs; this.name = name; };
i'm not familiar system
api, seems reasonable assume promise resolved module. access global variable console, can assign window
.
you mention using babel. babel assigns default export default
property of module:
system.import('client/app/animal/animal').then(function(module) { window.animal = module.default; });
Comments
Post a Comment