Snap.svg在这种情况下不起作用:
$('body').append($('<svg>').attr('id', 'test')) ;
console.log($('#test').length) ; // 1
var svg = Snap('#test') ;
svg.circle(100, 100, 50) ;
// Uncaught TypeError: Object [object Object] has no method 'circle'
Run Code Online (Sandbox Code Playgroud)
...但是当元素已经在HTML中时有效:
<body>
<svg id="test"></svg>
</body>
Run Code Online (Sandbox Code Playgroud)
SVG元素在HTML中成功,但在Snap.svg中找不到.我第一个例子做错了还是错误?
我想知道使用属性选择器而不是类选择器是否存在性能问题.
div.test {}
div[test] {}
Run Code Online (Sandbox Code Playgroud)
PS:我只对CSS性能感兴趣,而不是JS.
我希望创建一个构造函数的构造函数.关于这个线程:JavaScript构建构造函数的构造函数,似乎唯一的解决方案是:
Function.prototype.add = function(name, value) {
this.prototype[name] = value;
};
Function.prototype.remove = function(name) {
delete this.prototype[name];
};
Run Code Online (Sandbox Code Playgroud)
但我不想修改通用Function原型......还有:
var A = new ConstBuilder().add('test', function() {
console.log('test');
}).getConstructor();
Run Code Online (Sandbox Code Playgroud)
但我不想在构造函数本身周围有一个对象包装器.
问题是通常构造函数创建新对象,从构造函数原型继承方法.我想要做的是实现函数而不是对象,但修改函数原型属性的唯一方法是修改其__proto__属性:
var constructorPrototype = {
add : function(name, value) {
this.prototype[name] = value ;
}
} ;
var ConstBuilder = function() {
var constructor = function() {} ;
constructor.prototype = {} ;
// The only way (?), but quite deprecated...
constructor.__proto__ = constructorPrototype ;
return constructor …Run Code Online (Sandbox Code Playgroud) 我想知道为什么......
<script type="text/javascript">
define('test', [], function() {
alert('Done') ;
}) ;
</script>
Run Code Online (Sandbox Code Playgroud)
......不起作用.
我正在使用自己的Framework,如果可用的话,它使用RequireJS,并且要求define(name, dependencies, callback) ;加载每个需要另一个模块的模块.但有时模块没有依赖关系,所以dependencies是一个空数组.
除此之外我知道......
require([], function() {
alert('Done') ;
}) ;
Run Code Online (Sandbox Code Playgroud)
... 工作良好.
你能解释一下为什么第一种方法不起作用吗?谢谢.
使用构造函数工厂,我希望这些构造函数在控制台中具有不同的名称,在记录它们的实例时也是如此。
这是我的问题的一个简化示例:
// Constructor factory //
function type(name, prototype) {
function Constructor() {}
Constructor.name ; // "Constructor"
// Constructor.name = name won't work properly.
Object.defineProperty(Constructor, 'name', { value:name }) ;
Constructor.prototype = prototype ;
window[name] = Constructor ;
return Constructor ;
}
// Creating constructor and instance //
type('Cat', { name:"", paws:4 }) ;
var chat = new Cat ;
// Tests //
Cat.name ; // "Cat" -> Correct name
Cat ; // Constructor() { ... } -> Incorrect name …Run Code Online (Sandbox Code Playgroud) 为了防止编写一定量的代码,比如这个例子:
\n ...\n public getDataSet() : Observable<any>\n {\n return new Observable(observer => {\n if (this.dataset === undefined) {\n this.get().subscribe(data => {\n this.dataset = new DataSet(data) ;\n observer.next(this.dataset)\n observer.complete() ;\n }) ;\n }\n else {\n observer.next(this.dataset)\n observer.complete() ;\n }\n }) ;\n }\nRun Code Online (Sandbox Code Playgroud)\n我想使用async/await功能,但仍然返回一个 Observable 以在使用异步数据收集服务时保持一致。
\n因此根据 RxJs 的文档,我应该使用from()运算符。\n https://www.learnrxjs.io/learn-rxjs/operators/creation/from
这是我尝试实现的(看起来更简洁):
\nimport { Observable, from } from \'rxjs\' ;\n...\n return from(async () => { // \xe2\x9c\x98 error\n if (this.dataset === undefined) this.dataset = new …Run Code Online (Sandbox Code Playgroud) 我正在制作一个项目,用点和线(弯曲或不弯曲)制作简单的 3d 模型。对于第一个版本,我使用 SVG 元素进行简单渲染、平滑曲线和鼠标事件。
现在我正在尝试使用Three.js渲染器而不是 SVG。我必须创建 3d 管来替换曲线,但我不知道如何基于多个 xyz 坐标创建 3d 曲面。
这是一个由 4 个点和 4 条线(3 条直线和 1 条曲线)组成的模型示例:
我们可以想象曲线被挤压成更多的点,像这样:
然后我想创建一个表面(或平面),就像蓝色形状一样:
我受到了这个话题的启发:在three.js中将贝塞尔曲线转换为平面道路
var material = new THREE.MeshBasicMaterial({ color: 0xc0c0c0 });
var path = new THREE.CatmullRomCurve3([
new THREE.Vector3(dots[0].x, dots[0].y, -dots[0].z),
new THREE.Vector3(dots[1].x, dots[1].y, -dots[1].z),
new THREE.Vector3(dots[2].x, dots[2].y, -dots[2].z),
new THREE.Vector3(dots[3].x, dots[3].y, -dots[3].z),
new THREE.Vector3(dots[0].x, dots[0].y, -dots[0].z)
]);
var pts = [],
a ;
for (var i = 0 ; i < 3 ; i++) …Run Code Online (Sandbox Code Playgroud) 按照这个主题,我尝试生成一个3D弯曲三角形作为NURBS曲面,但是我不知道如何设置3D点来实现。
这是当前的实现:
var edges = this.getEdges(), // An edge is a line following 4 dots as a bezier curve.
dots = self.getDotsFromEdges(edges), // Get all dots in order for building the surface.
ctrlPoints = [ // Is generated only once before, but copy-pasted here for this sample code.
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, 0, 0, 1)
],
[
new THREE.Vector4(0, 0, 0, 1),
new THREE.Vector4(0, …Run Code Online (Sandbox Code Playgroud) javascript ×6
constructor ×2
nurbs ×2
three.js ×2
3d ×1
angular ×1
async-await ×1
bezier ×1
css ×1
cubic-bezier ×1
debugging ×1
jquery ×1
observable ×1
performance ×1
prototype ×1
requirejs ×1
rxjs ×1
snap.svg ×1
surface ×1
svg ×1
typescript ×1