小编J A*_*Any的帖子

Javascript是否通过引用传递?

Javascript是通过引用传递还是通过值传递?以下是Javascript:Good Parts的示例.我my对矩形函数的参数非常困惑.它实际上是undefined在函数内部重新定义的.没有原始参考.如果我从函数参数中删除它,则内部区域功能无法访问它.

是关闭吗?但是没有返回任何函数.

var shape = function (config) {
    var that = {};
    that.name = config.name || "";
    that.area = function () {
        return 0;
    };
    return that;
};
var rectangle = function (config, my) {
    my = my || {};
    my.l = config.length || 1;
    my.w = config.width || 1;
    var that = shape(config);
    that.area = function () {
        return my.l * my.w;
    };
    return that;
};
myShape = shape({
    name: "Unhnown"
}); …
Run Code Online (Sandbox Code Playgroud)

javascript reference pass-by-reference pass-by-value

340
推荐指数
8
解决办法
14万
查看次数

什么是函数(a,b)的值?

我正在测试JavaScrit的模块示例:好的部件.我不知道谁在a和b中传入了函数(a,b).不知怎的,它有效.

Function.prototype.method = function(name, f) {
    this.prototype[name] = f;
    return this;
}
String.method('de', function() {
    var entity = {
        lt : '<',
        gt : '>'
    };
    return function() {
        return this.replace(/&([^&;]+);/g, function(a, b) {
            document.write("<br> a=" + a + " b=" + b);
            var r = entity[b];
            return typeof r === 'string' ? r : a;
        });
    };
}());
document.write("<br>" + '&lt;&gt'.de());
Run Code Online (Sandbox Code Playgroud)

javascript concept

5
推荐指数
1
解决办法
323
查看次数

为什么instanceof在JavaScript中返回false?

在下面的代码中,为什么instanceof对Shape和Rectangle都返回false?为什么rec的属性包括超类中的x和y?

    function Shape(x, y) {
        this.x=x;
        this.y=y;
    }
    Shape.prototype.move = function (x, y) {
        this.x += x;
        this.y += y;
        console.log("x = " + this.x + " y = " + this.y);
    };
    function Rectangle(x, y, w, h) {
        Shape.call(this, x, y);
        this.w = w;
        this.h = h;
    }
    Rectangle.prototype = Object.create(Shape.prototype);
    Rectangle.prototype.area = function() {
        return this.w * this.h;
    };
    var rec = new Rectangle(0,0,10,10);
    console.log("instanceof = " + rec instanceof Shape);
    console.log("instanceof = " + rec instanceof Rectangle); …
Run Code Online (Sandbox Code Playgroud)

javascript

3
推荐指数
1
解决办法
718
查看次数

(function(){})有什么作用?

以下()做了什么?它似乎打印出里面的内容().

(function() {
    console.log("test");
});
Run Code Online (Sandbox Code Playgroud)

这就是ExtJS 4定义版本的方式:

(function() {

// Current core version
var version = '4.1.1', Version;
    Ext.Version = Version = Ext.extend(Object, {
    ...
});
Run Code Online (Sandbox Code Playgroud)

javascript function

-2
推荐指数
2
解决办法
347
查看次数