小编Jes*_* Vn的帖子

检查变量是否为函数类型

假设我有任何变量,定义如下:

var a = function() {/* Statements */};
Run Code Online (Sandbox Code Playgroud)

我想要一个函数来检查变量的类型是否像函数一样.即:

function foo(v) {if (v is function type?) {/* do something */}};
foo(a);
Run Code Online (Sandbox Code Playgroud)

如何以上面定义的方式检查变量a是否类型Function

javascript

826
推荐指数
14
解决办法
55万
查看次数

用C++创建正弦查找表

如何在C++中重写以下伪代码?

real array sine_table[-1000..1000]
    for x from -1000 to 1000
        sine_table[x] := sine(pi * x / 1000)
Run Code Online (Sandbox Code Playgroud)

我需要创建一个sine_table查找表.

c++ lookup trigonometry pseudocode

15
推荐指数
4
解决办法
3万
查看次数

从基类构造函数调用派生类的虚函数?

我正在尝试完成上一个问题中描述的相同内容:

从基类调用虚函数

但是,我真正的问题是:

如果f()是Base类中的构造函数怎么办?将调用哪个g()?我不知道我做错了,但在我的计划中,似乎是相反的.

从前一个问题中获取相同的变量,显示这样的代码

行为看起来像这样:

Class Base

{   

    Base(){g();};

    virtual void g(){//Do some Base related code;}

};



Class Derived : public Base

{   

    Derived(){};

    virtual void g(){//Do some Derived related code};

};



int main()

{

    Derived newDerived;

    return 0;  

}
Run Code Online (Sandbox Code Playgroud)

更新:

Thanx到Naveen.

他向我提供了一个页面,其中包含有关此主题的所有相关信息.

我会告诉你这里的链接:

parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.6

c++

15
推荐指数
1
解决办法
1万
查看次数

有没有办法使用Javascript合并两个路径元素(svg)?

我使用SVG绘制了两条路径,我在javascript代码中将这些元素保存为两个变量:'Line1'和'Line2',我需要将两行合并为一个单独的路径元素.有办法吗?

javascript svg

14
推荐指数
1
解决办法
2万
查看次数

是否可以直接使用jquery和Svg(没有插件)?

我正在尝试与Jquery和Svg一起工作.但我不想使用任何插件.

我现在要解决的问题是,当我尝试使用传统的追加模式将子项添加到svg文档时,该对象不会被渲染.让我们看一下我尝试做的事情:

/* Creating the svg container using pure JS */
var container = document.getElementById("svg_space");
mySvg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
mySvg.setAttribute("version", "1.2");
mySvg.setAttribute("baseProfile", "tiny");
container.appendChild(mySvg);

/* Adding a child and setting attributes to the SVG container using pure JS */
Circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
Circle.setAttribute("cx", "60");
Circle.setAttribute("cy", "30");
Circle.setAttribute("r", "13");
Circle.setAttribute("class", "class1");
    mySvg.appendChild(Circle); /* After this, the circle is rendered */

/* Then, I tried to use jQuery to perform the same action... */
$(mySvg).append("<circle />");
$(mySvg).find("circle").attr("cx","160");
$(mySvg).find("circle").attr("cy","70");
$(mySvg).find("circle").attr("r","30");
$(mySvg).find("circle").attr("class","class1" ); …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery svg dom

12
推荐指数
1
解决办法
2万
查看次数

从公共方法调用私有方法?

我定义了这样一个类:

function Class1(){
    this.Func1 = function(){
       /* Methods and vars */
    };

    function Func2(){
       /* Methods and vars */
    };

};
Run Code Online (Sandbox Code Playgroud)

我要寻找出路,从私人调用一个公共方法(或申请一个公共变量的值)(FUNC2()).任何sugestions?

Pd:很抱歉,如果我使用的术语强烈针对对象,因为我是一名C++程序员,而且我在javascript编程方面有点新手.

javascript

3
推荐指数
2
解决办法
8077
查看次数

标签 统计

javascript ×4

c++ ×2

svg ×2

dom ×1

html ×1

jquery ×1

lookup ×1

pseudocode ×1

trigonometry ×1